From: durk Date: Sun, 15 Jul 2007 14:08:31 +0000 (+0000) Subject: Fixes and code clean-up: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b452234cb203c3336cfc5299be8ff4789a0eb416;p=flightgear.git Fixes and code clean-up: - Airports Directory Thomas Foerster: Pulls out the FGTaxiNode implementation into gnnode.cxx. Melchior / Durk: Copy Constructor and assignment operator for FGTaxiRoute - AIModels Directory Durk / Melchior / Czaba Halasz: Ensure that all derived classes use AIBase member 'callsign'. Adapted, moved and deleted getter/setter functions where necessary Czaba Halasz: Fix AIBase model path vs. submodel path consistency. - Traffic Directory and AIModels CreateFlightPlanCruise DT: Temporary revert parts of the position estimation code. --- diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index 411b236c6..39c97f862 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -113,10 +113,6 @@ void FGAIAircraft::bind() { props->tie("controls/gear/gear-down", SGRawValueMethods(*this, &FGAIAircraft::_getGearDown)); - props->tie("callsign", - SGRawValueMethods(*this, - &FGAIAircraft::_getCallSign)); - //props->setStringValue("callsign", callsign.c_str()); } @@ -124,7 +120,6 @@ void FGAIAircraft::unbind() { FGAIBase::unbind(); props->untie("controls/gear/gear-down"); - props->untie("callsign"); } @@ -325,10 +320,6 @@ bool FGAIAircraft::_getGearDown() const { return _performance->gearExtensible(this); } -const char * FGAIAircraft::_getCallSign() const { - return callsign.c_str(); -} - void FGAIAircraft::loadNextLeg() { @@ -410,11 +401,6 @@ void FGAIAircraft::getGroundElev(double dt) { } -void FGAIAircraft::setCallSign(const string& s) { - callsign = s; -} - - void FGAIAircraft::doGroundAltitude() { if (fabs(altitude_ft - (tgt_altitude_ft+groundOffset)) > 1000.0) altitude_ft = (tgt_altitude_ft + groundOffset); diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index cf8e6babc..2105a4a73 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -61,8 +61,6 @@ public: void ClimbTo(double altitude); void TurnTo(double heading); - void setCallSign(const string& ); - void getGroundElev(double dt); //TODO these 3 really need to be public? void doGroundAltitude(); void loadNextLeg (); @@ -137,9 +135,8 @@ private: bool holdPos; bool _getGearDown() const; - const char *_getCallSign() const; + bool reachedWaypoint; - string callsign; // The callsign of this tanker. PerformanceData* _performance; // the performance data for this aircraft }; diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index e375f606c..289443902 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -245,6 +245,10 @@ void FGAIBase::bind() { SGRawValueMethods(*this, &FGAIBase::_getCartPosZ, 0)); + props->tie("callsign", + SGRawValueMethods(*this, + &FGAIBase::_getCallsign, + 0)); props->tie("orientation/pitch-deg", SGRawValuePointer(&pitch)); props->tie("orientation/roll-deg", SGRawValuePointer(&roll)); @@ -290,6 +294,7 @@ void FGAIBase::unbind() { props->untie("position/global-x"); props->untie("position/global-y"); props->untie("position/global-z"); + props->untie("callsign"); props->untie("orientation/pitch-deg"); props->untie("orientation/roll-deg"); @@ -581,19 +586,23 @@ double FGAIBase::_getHeading() const { return hdg; } -const char* FGAIBase::_getPath() { +const char* FGAIBase::_getPath() const { + return model_path.c_str(); +} + +const char* FGAIBase::_getSMPath() const { return _path.c_str(); } -const char* FGAIBase::_getName() { +const char* FGAIBase::_getName() const { return _name.c_str(); } -const char* FGAIBase::_getCallsign() { +const char* FGAIBase::_getCallsign() const { return _callsign.c_str(); } -const char* FGAIBase::_getSubmodel() { +const char* FGAIBase::_getSubmodel() const { return _submodel.c_str(); } @@ -621,7 +630,7 @@ void FGAIBase::CalculateMach() { // where: // a = speed of sound [ft/s] // g = specific heat ratio, which is usually equal to 1.4 - // R = specific gas constant, which equals 1716 ft-lb/slug/°R + // R = specific gas constant, which equals 1716 ft-lb/slug/R a = sqrt ( 1.4 * 1716 * (T + 459.7)); // calculate Mach number diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index f802c9937..d49336438 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -61,6 +61,7 @@ public: void setManager(FGAIManager* mgr, SGPropertyNode* p); void setPath( const char* model ); void setSMPath( const string& p ); + void setCallSign(const string& ); void setSpeed( double speed_KTAS ); void setAltitude( double altitude_ft ); void setHeading( double heading ); @@ -225,11 +226,12 @@ public: SGPropertyNode* _getProps() const; - const char* _getPath(); - const char* _getCallsign(); - const char* _getTriggerNode(); - const char* _getName(); - const char* _getSubmodel(); + const char* _getPath() const; + const char* _getSMPath() const; + const char* _getCallsign() const; + const char* _getTriggerNode() const; + const char* _getName() const; + const char* _getSubmodel() const; // These are used in the Mach number calculations @@ -305,6 +307,11 @@ inline void FGAIBase::setLatitude ( double latitude ) { pos.setLatitudeDeg( latitude ); } +inline void FGAIBase::setCallSign(const string& s) { + _callsign = s; +} + + inline void FGAIBase::setDie( bool die ) { delete_me = die; } inline bool FGAIBase::getDie() { return delete_me; } diff --git a/src/AIModel/AIFlightPlan.cxx b/src/AIModel/AIFlightPlan.cxx index 2d1887582..362604be2 100644 --- a/src/AIModel/AIFlightPlan.cxx +++ b/src/AIModel/AIFlightPlan.cxx @@ -192,8 +192,8 @@ FGAIFlightPlan::FGAIFlightPlan(const std::string& p, leg = 4; else if (timeDiff >= 2000) leg = 5; - - //cerr << "Set leg to : " << leg << endl; + + SG_LOG(SG_GENERAL, SG_INFO, "Route from " << dep->getId() << " to " << arr->getId() << ". Set leg to : " << leg); wpt_iterator = waypoints.begin(); create(dep,arr, leg, alt, speed, lat, lon, firstLeg, radius, fltType, acType, airline); diff --git a/src/AIModel/AIFlightPlanCreateCruise.cxx b/src/AIModel/AIFlightPlanCreateCruise.cxx index f9f39a518..0af5ed1fa 100755 --- a/src/AIModel/AIFlightPlanCreateCruise.cxx +++ b/src/AIModel/AIFlightPlanCreateCruise.cxx @@ -75,9 +75,15 @@ void FGAIFlightPlan::evaluateRoutePart(double deplat, } } //cerr << "1"<< endl; - SGGeoc geoc = SGGeoc::fromCart(SGVec3d(newPos[0], newPos[1], newPos[2])); - double midlat = geoc.getLatitudeDeg(); - double midlon = geoc.getLongitudeDeg(); + //SGGeoc geoc = SGGeoc::fromCart(SGVec3d(newPos[0], newPos[1], newPos[2])); + + //double midlat = geoc.getLatitudeDeg(); + //double midlon = geoc.getLongitudeDeg(); + + Point3D temp = sgCartToPolar3d(Point3D(newPos[0], newPos[1],newPos[2])); + double midlat = temp.lat() * SG_RADIANS_TO_DEGREES; + double midlon = temp.lon() * SG_RADIANS_TO_DEGREES; + prevNode = tmpNode; tmpNode = globals->get_airwaynet()->findNearestNode(midlat, midlon); diff --git a/src/AIModel/AIMultiplayer.cxx b/src/AIModel/AIMultiplayer.cxx index 717dc72af..b7b0f689c 100755 --- a/src/AIModel/AIMultiplayer.cxx +++ b/src/AIModel/AIMultiplayer.cxx @@ -48,7 +48,7 @@ bool FGAIMultiplayer::init(bool search_in_AI_path) { isTanker = false; // do this until this property is // passed over the net - string str1 = mCallSign; + string str1 = _getCallsign(); string str2 = "MOBIL"; string::size_type loc1= str1.find( str2, 0 ); @@ -73,7 +73,7 @@ SGRawValueMethods(*this, &FGAIMultiplayer::get##name) SGRawValueMethods(*this, \ &FGAIMultiplayer::get##name, &FGAIMultiplayer::set##name) - props->tie("callsign", AIMPROProp(const char *, CallSign)); + //props->tie("callsign", AIMPROProp(const char *, CallSign)); props->tie("controls/allow-extrapolation", AIMPRWProp(bool, AllowExtrapolation)); @@ -88,7 +88,7 @@ SGRawValueMethods(*this, \ void FGAIMultiplayer::unbind() { FGAIBase::unbind(); - props->untie("callsign"); + //props->untie("callsign"); props->untie("controls/allow-extrapolation"); props->untie("controls/lag-adjust-system-speed"); props->untie("refuel/contact"); diff --git a/src/AIModel/AIMultiplayer.hxx b/src/AIModel/AIMultiplayer.hxx index 596803a8d..6b30685aa 100755 --- a/src/AIModel/AIMultiplayer.hxx +++ b/src/AIModel/AIMultiplayer.hxx @@ -40,11 +40,6 @@ public: void addMotionInfo(const FGExternalMotionData& motionInfo, long stamp); void setDoubleProperty(const std::string& prop, double val); - void setCallSign(const string& callSign) - { mCallSign = callSign; } - const char* getCallSign(void) const - { return mCallSign.c_str(); } - long getLastTimestamp(void) const { return mLastTimestamp; } @@ -77,8 +72,6 @@ private: typedef std::map > PropertyMap; PropertyMap mPropertyMap; - std::string mCallSign; - double mTimeOffset; bool mTimeOffsetSet; diff --git a/src/AIModel/submodel.cxx b/src/AIModel/submodel.cxx index c158c05f8..7d065b8e1 100644 --- a/src/AIModel/submodel.cxx +++ b/src/AIModel/submodel.cxx @@ -517,7 +517,7 @@ void FGSubmodelMgr::loadAI() sm_list_iterator end = sm_list.end(); while (sm_list_itr != end) { - string path = (*sm_list_itr)->_getPath(); + string path = (*sm_list_itr)->_getSMPath(); if (path.empty()) { ++sm_list_itr; diff --git a/src/Airports/Makefile.am b/src/Airports/Makefile.am index 7f067295a..5cc6abe15 100644 --- a/src/Airports/Makefile.am +++ b/src/Airports/Makefile.am @@ -8,13 +8,13 @@ libAirports_a_SOURCES = \ simple.cxx simple.hxx \ runwayprefs.cxx runwayprefs.hxx \ parking.cxx parking.hxx \ + gnnode.cxx gnnode.hxx \ groundnetwork.cxx groundnetwork.hxx \ dynamics.cxx dynamics.hxx \ trafficcontrol.cxx trafficcontrol.hxx \ dynamicloader.cxx dynamicloader.hxx \ runwayprefloader.cxx runwayprefloader.hxx \ - xmlloader.cxx xmlloader.hxx \ - gnnode.hxx + xmlloader.cxx xmlloader.hxx calc_loc_SOURCES = calc_loc.cxx calc_loc_LDADD = -lsgmath -lsgdebug -lsgmisc -lz $(base_LIBS) diff --git a/src/Airports/gnnode.cxx b/src/Airports/gnnode.cxx new file mode 100644 index 000000000..b3b34d960 --- /dev/null +++ b/src/Airports/gnnode.cxx @@ -0,0 +1,55 @@ +#include "gnnode.hxx" +#include "groundnetwork.hxx" + +#include +SG_USING_STD(sort); + +/***************************************************************************** + * Helper function for parsing position string + ****************************************************************************/ +double processPosition(const string &pos) +{ + string prefix; + string subs; + string degree; + string decimal; + int sign = 1; + double value; + subs = pos; + prefix= subs.substr(0,1); + if (prefix == string("S") || (prefix == string("W"))) + sign = -1; + subs = subs.substr(1, subs.length()); + degree = subs.substr(0, subs.find(" ",0)); + decimal = subs.substr(subs.find(" ",0), subs.length()); + + + //cerr << sign << " "<< degree << " " << decimal << endl; + value = sign * (atof(degree.c_str()) + atof(decimal.c_str())/60.0); + //cerr << value <hasSmallerHeadingDiff(*b); +} + +bool sortByLength(FGTaxiSegment *a, FGTaxiSegment *b) { + return a->getLength() > b->getLength(); +} + +/************************************************************************** + * FGTaxiNode + *************************************************************************/ +FGTaxiNode::FGTaxiNode() +{ +} + +void FGTaxiNode::sortEndSegments(bool byLength) +{ + if (byLength) + sort(next.begin(), next.end(), sortByLength); + else + sort(next.begin(), next.end(), sortByHeadingDiff); +} diff --git a/src/Airports/gnnode.hxx b/src/Airports/gnnode.hxx index 703f1e46d..54dd66284 100644 --- a/src/Airports/gnnode.hxx +++ b/src/Airports/gnnode.hxx @@ -27,6 +27,8 @@ class FGTaxiSegment; typedef vector FGTaxiSegmentVector; typedef FGTaxiSegmentVector::iterator FGTaxiSegmentVectorIterator; +bool sortByHeadingDiff(FGTaxiSegment *a, FGTaxiSegment *b); +bool sortByLength (FGTaxiSegment *a, FGTaxiSegment *b); double processPosition(const string& pos); class FGTaxiNode diff --git a/src/Airports/groundnetwork.cxx b/src/Airports/groundnetwork.cxx index 397671cbb..9e26374aa 100644 --- a/src/Airports/groundnetwork.cxx +++ b/src/Airports/groundnetwork.cxx @@ -47,55 +47,6 @@ #include "groundnetwork.hxx" -SG_USING_STD(sort); - -/***************************************************************************** - * Helper function for parsing position string - ****************************************************************************/ -double processPosition(const string &pos) -{ - string prefix; - string subs; - string degree; - string decimal; - int sign = 1; - double value; - subs = pos; - prefix= subs.substr(0,1); - if (prefix == string("S") || (prefix == string("W"))) - sign = -1; - subs = subs.substr(1, subs.length()); - degree = subs.substr(0, subs.find(" ",0)); - decimal = subs.substr(subs.find(" ",0), subs.length()); - - - //cerr << sign << " "<< degree << " " << decimal << endl; - value = sign * (atof(degree.c_str()) + atof(decimal.c_str())/60.0); - //cerr << value <hasSmallerHeadingDiff(*b); -} -bool sortByLength(FGTaxiSegment *a, FGTaxiSegment *b) { - return a->getLength() > b->getLength(); -} /*************************************************************************** * FGTaxiRoute **************************************************************************/ @@ -249,6 +190,13 @@ void FGTaxiRoute::rewind(int route) /*************************************************************************** * FGGroundNetwork() **************************************************************************/ +bool compare_nodes(FGTaxiNode *a, FGTaxiNode *b) { +return (*a) < (*b); +} + +bool compare_segments(FGTaxiSegment *a, FGTaxiSegment *b) { +return (*a) < (*b); +} FGGroundNetwork::FGGroundNetwork() { diff --git a/src/Airports/groundnetwork.hxx b/src/Airports/groundnetwork.hxx index b9370fa21..3ed63e8c9 100644 --- a/src/Airports/groundnetwork.hxx +++ b/src/Airports/groundnetwork.hxx @@ -126,6 +126,26 @@ public: currNode = nodes.begin(); depth = dpth; }; + + FGTaxiRoute& operator= (const FGTaxiRoute &other) { + nodes = other.nodes; + routes = other.routes; + distance = other.distance; + depth = other.depth; + currNode = nodes.begin(); + currRoute = routes.begin(); + return *this; + }; + + FGTaxiRoute(const FGTaxiRoute& copy) : + nodes(copy.nodes), + routes(copy.routes), + distance(copy.distance), + depth(copy.depth), + currNode(nodes.begin()), + currRoute(routes.begin()) + {}; + bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; }; bool empty () { return nodes.begin() == nodes.end(); }; bool next(int *nde); @@ -140,10 +160,6 @@ public: typedef vector TaxiRouteVector; typedef vector::iterator TaxiRouteVectorIterator; -bool sortByHeadingDiff(FGTaxiSegment *a, FGTaxiSegment *b); -bool sortByLength (FGTaxiSegment *a, FGTaxiSegment *b); - - /************************************************************************************** * class FGGroundNetWork *************************************************************************************/ diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx index 35a1e44c9..fcb27479a 100644 --- a/src/Traffic/Schedule.cxx +++ b/src/Traffic/Schedule.cxx @@ -315,9 +315,14 @@ bool FGAISchedule::update(time_t now) if (now > (*i)->getDepartureTime()) { - SGGeoc geoc = SGGeoc::fromCart(newPos); - lat = geoc.getLatitudeDeg(); - lon = geoc.getLongitudeDeg(); + //SGGeoc geoc = SGGeoc::fromCart(newPos); + //lat = geoc.getLatitudeDeg(); + //lon = geoc.getLongitudeDeg(); + + Point3D temp = sgCartToPolar3d(Point3D(newPos[0], newPos[1],newPos[2])); + lat = temp.lat() * SG_RADIANS_TO_DEGREES; + lon = temp.lon() * SG_RADIANS_TO_DEGREES; + } else {