AIBase: Refactor
getTypeString returns string_view object_type to strongly-typed enum ModelSearchOrder to strongly-typed enum
This commit is contained in:
parent
42ee4822c7
commit
f198ac8d8d
30 changed files with 184 additions and 193 deletions
|
@ -104,7 +104,7 @@ FGAIAircraft::FGAIAircraft(FGAISchedule* ref) : /* HOT must be disabled for AI A
|
||||||
|
|
||||||
tcasThreatNode = props->getNode("tcas/threat-level", true);
|
tcasThreatNode = props->getNode("tcas/threat-level", true);
|
||||||
tcasRANode = props->getNode("tcas/ra-sense", true);
|
tcasRANode = props->getNode("tcas/ra-sense", true);
|
||||||
_searchOrder = PREFER_AI;
|
_searchOrder = ModelSearchOrder::PREFER_AI;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIAircraft::lazyInitControlsNodes()
|
void FGAIAircraft::lazyInitControlsNodes()
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "AIBaseAircraft.hxx"
|
#include "AIBaseAircraft.hxx"
|
||||||
|
@ -38,7 +39,7 @@ public:
|
||||||
FGAIAircraft(FGAISchedule *ref=0);
|
FGAIAircraft(FGAISchedule *ref=0);
|
||||||
virtual ~FGAIAircraft();
|
virtual ~FGAIAircraft();
|
||||||
|
|
||||||
const char* getTypeString(void) const override { return "aircraft"; }
|
string_view getTypeString(void) const override { return "aircraft"; }
|
||||||
void readFromScenario(SGPropertyNode* scFileNode) override;
|
void readFromScenario(SGPropertyNode* scFileNode) override;
|
||||||
|
|
||||||
void bind() override;
|
void bind() override;
|
||||||
|
|
|
@ -996,7 +996,7 @@ void FGAIBallistic::report_impact(double elevation, const FGAIBase *object)
|
||||||
SGPropertyNode *n = props->getNode("impact", true);
|
SGPropertyNode *n = props->getNode("impact", true);
|
||||||
|
|
||||||
if (object)
|
if (object)
|
||||||
n->setStringValue("type", object->getTypeString());
|
n->setStringValue("type", static_cast<std::string>(object->getTypeString()));
|
||||||
else
|
else
|
||||||
n->setStringValue("type", "terrain");
|
n->setStringValue("type", "terrain");
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <simgear/structure/SGSharedPtr.hxx>
|
#include <simgear/structure/SGSharedPtr.hxx>
|
||||||
|
@ -34,10 +35,10 @@ class FGAIBallistic : public FGAIBase {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FGAIBallistic(object_type ot = otBallistic);
|
FGAIBallistic(object_type ot = object_type::otBallistic);
|
||||||
virtual ~FGAIBallistic() = default;
|
virtual ~FGAIBallistic() = default;
|
||||||
|
|
||||||
const char* getTypeString(void) const override { return "ballistic"; }
|
string_view getTypeString(void) const override { return "ballistic"; }
|
||||||
void readFromScenario(SGPropertyNode* scFileNode) override;
|
void readFromScenario(SGPropertyNode* scFileNode) override;
|
||||||
|
|
||||||
bool init(ModelSearchOrder searchOrder) override;
|
bool init(ModelSearchOrder searchOrder) override;
|
||||||
|
|
|
@ -144,18 +144,18 @@ private:
|
||||||
ErrorContext _errorContext;
|
ErrorContext _errorContext;
|
||||||
};
|
};
|
||||||
|
|
||||||
FGAIBase::FGAIBase(object_type ot, bool enableHot) :
|
FGAIBase::FGAIBase(object_type ot, bool enableHot) : replay_time(fgGetNode("sim/replay/time", true)),
|
||||||
replay_time(fgGetNode("sim/replay/time", true)),
|
model_removed(fgGetNode("/ai/models/model-removed", true)),
|
||||||
model_removed( fgGetNode("/ai/models/model-removed", true) ),
|
pos(SGGeod::fromDeg(0.0, 0.0)),
|
||||||
_impact_lat(0),
|
_impact_lat(0),
|
||||||
_impact_lon(0),
|
_impact_lon(0),
|
||||||
_impact_elev(0),
|
_impact_elev(0),
|
||||||
_impact_hdg(0),
|
_impact_hdg(0),
|
||||||
_impact_pitch(0),
|
_impact_pitch(0),
|
||||||
_impact_roll(0),
|
_impact_roll(0),
|
||||||
_impact_speed(0),
|
_impact_speed(0),
|
||||||
_refID( _newAIModelID() ),
|
_refID(_newAIModelID()),
|
||||||
_otype(ot)
|
_otype(ot)
|
||||||
{
|
{
|
||||||
tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0;
|
tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0;
|
||||||
tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs_fps = pitch = 0.0;
|
tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs_fps = pitch = 0.0;
|
||||||
|
@ -178,7 +178,6 @@ FGAIBase::FGAIBase(object_type ot, bool enableHot) :
|
||||||
_roll_offset = 0;
|
_roll_offset = 0;
|
||||||
_yaw_offset = 0;
|
_yaw_offset = 0;
|
||||||
|
|
||||||
pos = SGGeod::fromDeg(0, 0);
|
|
||||||
speed = 0;
|
speed = 0;
|
||||||
altitude_ft = 0;
|
altitude_ft = 0;
|
||||||
speed_north_deg_sec = 0;
|
speed_north_deg_sec = 0;
|
||||||
|
@ -285,14 +284,13 @@ void FGAIBase::readFromScenario(SGPropertyNode* scFileNode)
|
||||||
string searchOrder = scFileNode->getStringValue("search-order", "");
|
string searchOrder = scFileNode->getStringValue("search-order", "");
|
||||||
if (!searchOrder.empty()) {
|
if (!searchOrder.empty()) {
|
||||||
if (searchOrder == "DATA_ONLY") {
|
if (searchOrder == "DATA_ONLY") {
|
||||||
_searchOrder = DATA_ONLY;
|
_searchOrder = ModelSearchOrder::DATA_ONLY;
|
||||||
} else if (searchOrder == "PREFER_AI") {
|
} else if (searchOrder == "PREFER_AI") {
|
||||||
_searchOrder = PREFER_AI;
|
_searchOrder = ModelSearchOrder::PREFER_AI;
|
||||||
} else if (searchOrder == "PREFER_DATA") {
|
} else if (searchOrder == "PREFER_DATA") {
|
||||||
_searchOrder = PREFER_DATA;
|
_searchOrder = ModelSearchOrder::PREFER_DATA;
|
||||||
} else
|
} else
|
||||||
SG_LOG(SG_AI, SG_WARN, "invalid model search order " << searchOrder << ". Use either DATA_ONLY, PREFER_AI or PREFER_DATA");
|
SG_LOG(SG_AI, SG_WARN, "invalid model search order " << searchOrder << ". Use either DATA_ONLY, PREFER_AI or PREFER_DATA");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const string modelLowres = scFileNode->getStringValue("model-lowres", "");
|
const string modelLowres = scFileNode->getStringValue("model-lowres", "");
|
||||||
|
@ -306,10 +304,10 @@ void FGAIBase::update(double dt) {
|
||||||
SG_UNUSED(dt);
|
SG_UNUSED(dt);
|
||||||
if (replay_time->getDoubleValue() > 0)
|
if (replay_time->getDoubleValue() > 0)
|
||||||
return;
|
return;
|
||||||
if (_otype == otStatic)
|
if (_otype == object_type::otStatic)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_otype == otBallistic)
|
if (_otype == object_type::otBallistic)
|
||||||
CalculateMach();
|
CalculateMach();
|
||||||
|
|
||||||
ft_per_deg_lat = 366468.96 - 3717.12 * cos(pos.getLatitudeRad());
|
ft_per_deg_lat = 366468.96 - 3717.12 * cos(pos.getLatitudeRad());
|
||||||
|
@ -558,7 +556,7 @@ std::vector<std::string> FGAIBase::resolveModelPath(ModelSearchOrder searchOrder
|
||||||
{
|
{
|
||||||
string_list path_list;
|
string_list path_list;
|
||||||
|
|
||||||
if (searchOrder == DATA_ONLY) {
|
if (searchOrder == ModelSearchOrder::DATA_ONLY) {
|
||||||
SG_LOG(SG_AI, SG_DEBUG, "Resolving model path: DATA only");
|
SG_LOG(SG_AI, SG_DEBUG, "Resolving model path: DATA only");
|
||||||
auto p = simgear::SGModelLib::findDataFile(model_path);
|
auto p = simgear::SGModelLib::findDataFile(model_path);
|
||||||
if (!p.empty()) {
|
if (!p.empty()) {
|
||||||
|
@ -614,7 +612,7 @@ std::vector<std::string> FGAIBase::resolveModelPath(ModelSearchOrder searchOrder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((searchOrder == PREFER_AI) && !path_list.empty()) {
|
if ((searchOrder == ModelSearchOrder::PREFER_AI) && !path_list.empty()) {
|
||||||
// if we prefer AI, and we've got a valid AI path from above, then use it, we're done
|
// if we prefer AI, and we've got a valid AI path from above, then use it, we're done
|
||||||
_installed = true;
|
_installed = true;
|
||||||
return path_list;
|
return path_list;
|
||||||
|
@ -657,7 +655,7 @@ bool FGAIBase::init(ModelSearchOrder searchOrder)
|
||||||
// set by FGAISchedule::createAIAircraft
|
// set by FGAISchedule::createAIAircraft
|
||||||
_modeldata->captureErrorContext("traffic-aircraft-callsign");
|
_modeldata->captureErrorContext("traffic-aircraft-callsign");
|
||||||
|
|
||||||
if (_otype == otMultiplayer) {
|
if (_otype == object_type::otMultiplayer) {
|
||||||
_modeldata->addErrorContext("multiplayer", getCallSign());
|
_modeldata->addErrorContext("multiplayer", getCallSign());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -995,10 +993,8 @@ void FGAIBase::_setSubID( int s ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FGAIBase::setParentNode() {
|
bool FGAIBase::setParentNode() {
|
||||||
|
|
||||||
if (_parent == ""){
|
if (_parent == ""){
|
||||||
SG_LOG(SG_AI, SG_ALERT, "AIBase: " << _name
|
SG_LOG(SG_AI, SG_ALERT, "AIBase: " << _name << " parent not set ");
|
||||||
<< " parent not set ");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1011,33 +1007,30 @@ bool FGAIBase::setParentNode() {
|
||||||
model = _selected_ac;
|
model = _selected_ac;
|
||||||
} else {
|
} else {
|
||||||
model = ai->getChild(i);
|
model = ai->getChild(i);
|
||||||
//const string& path = ai->getPath();
|
|
||||||
const string name = model->getStringValue("name");
|
const string name = model->getStringValue("name");
|
||||||
|
|
||||||
if (!model->nChildren()){
|
if (!model->nChildren()){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == _parent) {
|
if (name == _parent) {
|
||||||
_selected_ac = model; // save selected model for last iteration
|
_selected_ac = model; // save selected model for last iteration
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!model)
|
if (!model)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
}// end for loop
|
}// end for loop
|
||||||
|
|
||||||
if (_selected_ac != 0){
|
if (_selected_ac != 0){
|
||||||
const string name = _selected_ac->getStringValue("name");
|
// DEADCODE: const string name = _selected_ac->getStringValue("name");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
SG_LOG(SG_AI, SG_ALERT, "AIBase: " << _name
|
SG_LOG(SG_AI, SG_ALERT, "AIBase: " << _name << " parent not found: dying ");
|
||||||
<< " parent not found: dying ");
|
|
||||||
setDie(true);
|
setDie(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double FGAIBase::_getLongitude() const {
|
double FGAIBase::_getLongitude() const {
|
||||||
|
|
|
@ -17,40 +17,50 @@
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
#ifndef FG_AIBASE_HXX
|
#pragma once
|
||||||
#define FG_AIBASE_HXX
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <osg/ref_ptr>
|
#include <osg/ref_ptr>
|
||||||
|
|
||||||
#include <simgear/constants.h>
|
#include <simgear/constants.h>
|
||||||
#include <simgear/scene/model/placement.hxx>
|
|
||||||
#include <simgear/misc/sg_path.hxx>
|
|
||||||
#include <simgear/structure/SGSharedPtr.hxx>
|
|
||||||
#include <simgear/structure/SGReferenced.hxx>
|
|
||||||
#include <simgear/props/tiedpropertylist.hxx>
|
|
||||||
#include <simgear/sg_inlines.h>
|
|
||||||
|
|
||||||
#include <simgear/math/sg_geodesy.hxx>
|
#include <simgear/math/sg_geodesy.hxx>
|
||||||
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
#include <simgear/props/tiedpropertylist.hxx>
|
||||||
|
#include <simgear/scene/model/placement.hxx>
|
||||||
|
#include <simgear/sg_inlines.h>
|
||||||
|
#include <simgear/structure/SGReferenced.hxx>
|
||||||
|
#include <simgear/structure/SGSharedPtr.hxx>
|
||||||
|
|
||||||
namespace osg { class PagedLOD; }
|
namespace osg { class PagedLOD; }
|
||||||
|
namespace simgear { class BVHMaterial; }
|
||||||
|
|
||||||
namespace simgear {
|
|
||||||
class BVHMaterial;
|
|
||||||
}
|
|
||||||
class FGAIManager;
|
class FGAIManager;
|
||||||
class FGAIFlightPlan;
|
class FGAIFlightPlan;
|
||||||
class FGFX;
|
class FGFX;
|
||||||
class FGAIModelData; // defined below
|
class FGAIModelData; // defined below
|
||||||
|
|
||||||
|
|
||||||
class FGAIBase : public SGReferenced {
|
class FGAIBase : public SGReferenced
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic,
|
enum class object_type {
|
||||||
otRocket, otStorm, otThermal, otStatic, otWingman, otGroundVehicle,
|
otNull = 0,
|
||||||
otEscort, otMultiplayer,
|
otAircraft,
|
||||||
MAX_OBJECTS }; // Needs to be last!!!
|
otShip,
|
||||||
|
otCarrier,
|
||||||
|
otBallistic,
|
||||||
|
otRocket,
|
||||||
|
otStorm,
|
||||||
|
otThermal,
|
||||||
|
otStatic,
|
||||||
|
otWingman,
|
||||||
|
otGroundVehicle,
|
||||||
|
otEscort,
|
||||||
|
otMultiplayer,
|
||||||
|
MAX_OBJECTS // Needs to be last!!!
|
||||||
|
};
|
||||||
|
|
||||||
FGAIBase(object_type ot, bool enableHot);
|
FGAIBase(object_type ot, bool enableHot);
|
||||||
virtual ~FGAIBase();
|
virtual ~FGAIBase();
|
||||||
|
@ -63,7 +73,7 @@ public:
|
||||||
|
|
||||||
virtual void readFromScenario(SGPropertyNode* scFileNode);
|
virtual void readFromScenario(SGPropertyNode* scFileNode);
|
||||||
|
|
||||||
enum ModelSearchOrder {
|
enum class ModelSearchOrder {
|
||||||
DATA_ONLY, // don't search AI/ prefix at all
|
DATA_ONLY, // don't search AI/ prefix at all
|
||||||
PREFER_AI, // search AI first, override other paths
|
PREFER_AI, // search AI first, override other paths
|
||||||
PREFER_DATA // search data first but fall back to AI
|
PREFER_DATA // search data first but fall back to AI
|
||||||
|
@ -75,41 +85,58 @@ public:
|
||||||
virtual void bind();
|
virtual void bind();
|
||||||
virtual void unbind();
|
virtual void unbind();
|
||||||
virtual void reinit() {}
|
virtual void reinit() {}
|
||||||
|
|
||||||
// default model radius for LOD.
|
// default model radius for LOD.
|
||||||
virtual double getDefaultModelRadius() { return 20.0; }
|
virtual double getDefaultModelRadius() { return 20.0; }
|
||||||
|
|
||||||
void updateLOD();
|
void updateLOD();
|
||||||
void updateInterior();
|
void updateInterior();
|
||||||
|
|
||||||
void setManager(FGAIManager* mgr, SGPropertyNode* p);
|
void setManager(FGAIManager* mgr, SGPropertyNode* p);
|
||||||
|
|
||||||
void setPath( const char* model );
|
void setPath( const char* model );
|
||||||
void setPathLowres( std::string model );
|
void setPathLowres( std::string model );
|
||||||
|
|
||||||
void setFallbackModelIndex(const int i );
|
void setFallbackModelIndex(const int i );
|
||||||
void setSMPath( const std::string& p );
|
void setSMPath( const std::string& p );
|
||||||
void setCallSign(const std::string& );
|
void setCallSign(const std::string& );
|
||||||
|
|
||||||
void setSpeed( double speed_KTAS );
|
void setSpeed( double speed_KTAS );
|
||||||
|
void setMaxSpeed(double kts);
|
||||||
|
|
||||||
void setAltitude( double altitude_ft );
|
void setAltitude( double altitude_ft );
|
||||||
void setAltitudeAGL( double altitude_agl_ft );
|
void setAltitudeAGL( double altitude_agl_ft );
|
||||||
void setHeading( double heading );
|
void setHeading( double heading );
|
||||||
void setLatitude( double latitude );
|
void setLatitude( double latitude );
|
||||||
void setLongitude( double longitude );
|
void setLongitude( double longitude );
|
||||||
|
|
||||||
void setBank( double bank );
|
void setBank( double bank );
|
||||||
void setPitch( double newpitch );
|
void setPitch( double newpitch );
|
||||||
void setRadius ( double radius );
|
void setRadius ( double radius );
|
||||||
|
|
||||||
void setXoffset( double x_offset );
|
void setXoffset( double x_offset );
|
||||||
void setYoffset( double y_offset );
|
void setYoffset( double y_offset );
|
||||||
void setZoffset( double z_offset );
|
void setZoffset( double z_offset );
|
||||||
|
|
||||||
void setPitchoffset( double x_offset );
|
void setPitchoffset( double x_offset );
|
||||||
void setRolloffset( double y_offset );
|
void setRolloffset( double y_offset );
|
||||||
void setYawoffset( double z_offset );
|
void setYawoffset( double z_offset );
|
||||||
|
|
||||||
void setServiceable ( bool serviceable );
|
void setServiceable ( bool serviceable );
|
||||||
|
|
||||||
|
bool getDie();
|
||||||
void setDie( bool die );
|
void setDie( bool die );
|
||||||
|
bool isValid() const;
|
||||||
|
|
||||||
void setCollisionData( bool i, double lat, double lon, double elev );
|
void setCollisionData( bool i, double lat, double lon, double elev );
|
||||||
void setImpactData( bool d );
|
void setImpactData( bool d );
|
||||||
void setImpactLat( double lat );
|
void setImpactLat( double lat );
|
||||||
void setImpactLon( double lon );
|
void setImpactLon( double lon );
|
||||||
void setImpactElev( double e );
|
void setImpactElev( double e );
|
||||||
void setParentName(const std::string& p);
|
|
||||||
void setName(const std::string& n);
|
void setName(const std::string& n);
|
||||||
void setMaxSpeed(double kts);
|
bool setParentNode();
|
||||||
|
void setParentName(const std::string& p);
|
||||||
|
|
||||||
void calcRangeBearing(double lat, double lon, double lat2, double lon2,
|
void calcRangeBearing(double lat, double lon, double lat2, double lon2,
|
||||||
double &range, double &bearing) const;
|
double &range, double &bearing) const;
|
||||||
|
@ -117,19 +144,13 @@ public:
|
||||||
double calcTrueBearingDeg(double bearing, double heading);
|
double calcTrueBearingDeg(double bearing, double heading);
|
||||||
double calcRecipBearingDeg(double bearing);
|
double calcRecipBearingDeg(double bearing);
|
||||||
|
|
||||||
bool setParentNode();
|
|
||||||
|
|
||||||
int getID() const;
|
int getID() const;
|
||||||
int _getSubID() const;
|
int _getSubID() const;
|
||||||
|
|
||||||
bool getDie();
|
|
||||||
bool isValid() const;
|
|
||||||
|
|
||||||
void setFlightPlan(std::unique_ptr<FGAIFlightPlan> f);
|
void setFlightPlan(std::unique_ptr<FGAIFlightPlan> f);
|
||||||
|
|
||||||
SGGeod getGeodPos() const;
|
SGGeod getGeodPos() const;
|
||||||
void setGeodPos(const SGGeod& pos);
|
void setGeodPos(const SGGeod& pos);
|
||||||
|
|
||||||
SGVec3d getCartPosAt(const SGVec3d& off) const;
|
SGVec3d getCartPosAt(const SGVec3d& off) const;
|
||||||
SGVec3d getCartPos() const;
|
SGVec3d getCartPos() const;
|
||||||
|
|
||||||
|
@ -138,10 +159,7 @@ public:
|
||||||
|
|
||||||
SGPropertyNode* getPositionFromNode(SGPropertyNode* scFileNode, const std::string& key, SGVec3d& position);
|
SGPropertyNode* getPositionFromNode(SGPropertyNode* scFileNode, const std::string& key, SGVec3d& position);
|
||||||
|
|
||||||
double getTrueHeadingDeg() const
|
double getTrueHeadingDeg() const { return hdg; }
|
||||||
{
|
|
||||||
return hdg;
|
|
||||||
}
|
|
||||||
|
|
||||||
double _getCartPosX() const;
|
double _getCartPosX() const;
|
||||||
double _getCartPosY() const;
|
double _getCartPosY() const;
|
||||||
|
@ -158,9 +176,9 @@ public:
|
||||||
void setScenarioPath(const std::string& scenarioPath);
|
void setScenarioPath(const std::string& scenarioPath);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double _elevation_m;
|
double _elevation_m = 0.0;
|
||||||
|
|
||||||
double _maxRangeInterior;
|
double _maxRangeInterior = 50.0;
|
||||||
|
|
||||||
double _x_offset;
|
double _x_offset;
|
||||||
double _y_offset;
|
double _y_offset;
|
||||||
|
@ -202,13 +220,13 @@ protected:
|
||||||
double roll; // degrees, left is negative
|
double roll; // degrees, left is negative
|
||||||
double pitch; // degrees, nose-down is negative
|
double pitch; // degrees, nose-down is negative
|
||||||
double speed; // knots true airspeed
|
double speed; // knots true airspeed
|
||||||
double speed_fps; // fps true airspeed
|
double speed_fps = 0.0; // fps true airspeed
|
||||||
double altitude_ft; // feet above sea level
|
double altitude_ft; // feet above sea level
|
||||||
double vs_fps; // vertical speed
|
double vs_fps; // vertical speed
|
||||||
double speed_north_deg_sec;
|
double speed_north_deg_sec;
|
||||||
double speed_east_deg_sec;
|
double speed_east_deg_sec;
|
||||||
double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
|
double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
|
||||||
double altitude_agl_ft;
|
double altitude_agl_ft = 0.0;
|
||||||
|
|
||||||
double ft_per_deg_lon;
|
double ft_per_deg_lon;
|
||||||
double ft_per_deg_lat;
|
double ft_per_deg_lat;
|
||||||
|
@ -235,13 +253,13 @@ protected:
|
||||||
double rotation; // value used by radar display instrument
|
double rotation; // value used by radar display instrument
|
||||||
double ht_diff; // value used by radar display instrument
|
double ht_diff; // value used by radar display instrument
|
||||||
|
|
||||||
std::string model_path; // Path to the 3D model
|
std::string model_path; // Path to the 3D model
|
||||||
std::string model_path_lowres; // Path to optional low res 3D model
|
std::string model_path_lowres; // Path to optional low res 3D model
|
||||||
int _fallback_model_index; // Index into /sim/multiplay/fallback-models[]
|
int _fallback_model_index = 0; // Index into /sim/multiplay/fallback-models[]
|
||||||
SGModelPlacement aip;
|
SGModelPlacement aip;
|
||||||
|
|
||||||
bool delete_me;
|
bool delete_me;
|
||||||
bool invisible;
|
bool invisible = false;
|
||||||
bool no_roll;
|
bool no_roll;
|
||||||
bool serviceable;
|
bool serviceable;
|
||||||
bool _installed = false;
|
bool _installed = false;
|
||||||
|
@ -263,7 +281,7 @@ protected:
|
||||||
double _impact_roll;
|
double _impact_roll;
|
||||||
double _impact_speed;
|
double _impact_speed;
|
||||||
|
|
||||||
ModelSearchOrder _searchOrder = DATA_ONLY;
|
ModelSearchOrder _searchOrder = ModelSearchOrder::DATA_ONLY;
|
||||||
void Transform();
|
void Transform();
|
||||||
void CalculateMach();
|
void CalculateMach();
|
||||||
double UpdateRadar(FGAIManager* manager);
|
double UpdateRadar(FGAIManager* manager);
|
||||||
|
@ -292,7 +310,7 @@ private:
|
||||||
public:
|
public:
|
||||||
object_type getType();
|
object_type getType();
|
||||||
|
|
||||||
virtual const char* getTypeString(void) const { return "null"; }
|
virtual string_view getTypeString(void) const { return "null"; }
|
||||||
|
|
||||||
bool isa( object_type otype );
|
bool isa( object_type otype );
|
||||||
|
|
||||||
|
@ -332,7 +350,6 @@ public:
|
||||||
double _getXOffset() const;
|
double _getXOffset() const;
|
||||||
double _getYOffset() const;
|
double _getYOffset() const;
|
||||||
double _getZOffset() const;
|
double _getZOffset() const;
|
||||||
//unsigned int _getCount() const;
|
|
||||||
|
|
||||||
bool _getServiceable() const;
|
bool _getServiceable() const;
|
||||||
bool _getFirstTime() const;
|
bool _getFirstTime() const;
|
||||||
|
@ -366,8 +383,7 @@ public:
|
||||||
|
|
||||||
static bool _isNight();
|
static bool _isNight();
|
||||||
|
|
||||||
const std::string& getCallSign() const
|
const std::string& getCallSign() const { return _callsign; }
|
||||||
{ return _callsign; }
|
|
||||||
ModelSearchOrder getSearchOrder() const {return _searchOrder;}
|
ModelSearchOrder getSearchOrder() const {return _searchOrder;}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -509,5 +525,3 @@ inline void FGAIBase::setMaxSpeed(double m) {
|
||||||
_max_speed = m;
|
_max_speed = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // _FG_AIBASE_HXX
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class FGAIBaseAircraft : public FGAIBase
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FGAIBaseAircraft(object_type otype = FGAIBase::otAircraft);
|
FGAIBaseAircraft(object_type otype = object_type::otAircraft);
|
||||||
|
|
||||||
void bind() override;
|
void bind() override;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#include "AICarrier.hxx"
|
#include "AICarrier.hxx"
|
||||||
#include "AINotifications.hxx"
|
#include "AINotifications.hxx"
|
||||||
|
|
||||||
FGAICarrier::FGAICarrier() : FGAIShip(otCarrier)
|
FGAICarrier::FGAICarrier() : FGAIShip(object_type::otCarrier)
|
||||||
{
|
{
|
||||||
simgear::Emesary::GlobalTransmitter::instance()->Register(this);
|
simgear::Emesary::GlobalTransmitter::instance()->Register(this);
|
||||||
}
|
}
|
||||||
|
@ -807,7 +807,7 @@ SGSharedPtr<FGAICarrier> FGAICarrier::findCarrierByNameOrPennant(const std::stri
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& aiObject : aiManager->get_ai_list()) {
|
for (const auto& aiObject : aiManager->get_ai_list()) {
|
||||||
if (aiObject->isa(FGAIBase::otCarrier)) {
|
if (aiObject->isa(object_type::otCarrier)) {
|
||||||
SGSharedPtr<FGAICarrier> c = static_cast<FGAICarrier*>(aiObject.get());
|
SGSharedPtr<FGAICarrier> c = static_cast<FGAICarrier*>(aiObject.get());
|
||||||
if ((c->_sign == namePennant) || (c->_getName() == namePennant)) {
|
if ((c->_sign == namePennant) || (c->_getName() == namePennant)) {
|
||||||
return c;
|
return c;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
#include <simgear/emesary/Emesary.hxx>
|
#include <simgear/emesary/Emesary.hxx>
|
||||||
|
@ -40,6 +41,7 @@ public:
|
||||||
FGAICarrier();
|
FGAICarrier();
|
||||||
virtual ~FGAICarrier();
|
virtual ~FGAICarrier();
|
||||||
|
|
||||||
|
string_view getTypeString(void) const override { return "carrier"; }
|
||||||
void readFromScenario(SGPropertyNode* scFileNode) override;
|
void readFromScenario(SGPropertyNode* scFileNode) override;
|
||||||
|
|
||||||
void setSign(const std::string&);
|
void setSign(const std::string&);
|
||||||
|
@ -65,8 +67,6 @@ public:
|
||||||
|
|
||||||
bool init(ModelSearchOrder searchOrder) override;
|
bool init(ModelSearchOrder searchOrder) override;
|
||||||
|
|
||||||
const char* getTypeString(void) const override { return "carrier"; }
|
|
||||||
|
|
||||||
bool getParkPosition(const std::string& id, SGGeod& geodPos, double& hdng, SGVec3d& uvw);
|
bool getParkPosition(const std::string& id, SGGeod& geodPos, double& hdng, SGVec3d& uvw);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,6 +102,7 @@ private:
|
||||||
: name(n), offset(off), heading_deg(heading)
|
: name(n), offset(off), heading_deg(heading)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
SGVec3d offset;
|
SGVec3d offset;
|
||||||
double heading_deg;
|
double heading_deg;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ public:
|
||||||
FGAIEscort();
|
FGAIEscort();
|
||||||
virtual ~FGAIEscort() = default;
|
virtual ~FGAIEscort() = default;
|
||||||
|
|
||||||
const char* getTypeString(void) const override { return "escort"; }
|
string_view getTypeString(void) const override { return "escort"; }
|
||||||
void readFromScenario(SGPropertyNode* scFileNode) override;
|
void readFromScenario(SGPropertyNode* scFileNode) override;
|
||||||
|
|
||||||
bool init(ModelSearchOrder searchOrder) override;
|
bool init(ModelSearchOrder searchOrder) override;
|
||||||
|
@ -96,4 +97,3 @@ private:
|
||||||
bool _patrol = false;
|
bool _patrol = false;
|
||||||
bool _stn_deg_true = false;
|
bool _stn_deg_true = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <simgear/structure/SGSharedPtr.hxx>
|
#include <simgear/structure/SGSharedPtr.hxx>
|
||||||
|
@ -36,7 +37,7 @@ public:
|
||||||
FGAIGroundVehicle();
|
FGAIGroundVehicle();
|
||||||
virtual ~FGAIGroundVehicle() = default;
|
virtual ~FGAIGroundVehicle() = default;
|
||||||
|
|
||||||
const char* getTypeString(void) const override { return "groundvehicle"; }
|
string_view getTypeString(void) const override { return "groundvehicle"; }
|
||||||
void readFromScenario(SGPropertyNode* scFileNode) override;
|
void readFromScenario(SGPropertyNode* scFileNode) override;
|
||||||
|
|
||||||
bool init(ModelSearchOrder searchOrder) override;
|
bool init(ModelSearchOrder searchOrder) override;
|
||||||
|
|
|
@ -399,7 +399,7 @@ FGAIManager::update(double dt)
|
||||||
// entire subsystem.
|
// entire subsystem.
|
||||||
for (FGAIBase* base : ai_list) {
|
for (FGAIBase* base : ai_list) {
|
||||||
try {
|
try {
|
||||||
if (base->isa(FGAIBase::otThermal)) {
|
if (base->isa(FGAIBase::object_type::otThermal)) {
|
||||||
processThermal(dt, static_cast<FGAIThermal*>(base));
|
processThermal(dt, static_cast<FGAIThermal*>(base));
|
||||||
} else {
|
} else {
|
||||||
base->update(dt);
|
base->update(dt);
|
||||||
|
@ -425,7 +425,7 @@ FGAIManager::updateLOD(SGPropertyNode* node)
|
||||||
void
|
void
|
||||||
FGAIManager::attach(const SGSharedPtr<FGAIBase> &model)
|
FGAIManager::attach(const SGSharedPtr<FGAIBase> &model)
|
||||||
{
|
{
|
||||||
const char* typeString = model->getTypeString();
|
string_view typeString = model->getTypeString();
|
||||||
SGPropertyNode* root = globals->get_props()->getNode("ai/models", true);
|
SGPropertyNode* root = globals->get_props()->getNode("ai/models", true);
|
||||||
SGPropertyNode* p;
|
SGPropertyNode* p;
|
||||||
int i;
|
int i;
|
||||||
|
@ -433,7 +433,7 @@ FGAIManager::attach(const SGSharedPtr<FGAIBase> &model)
|
||||||
// find free index in the property tree, if we have
|
// find free index in the property tree, if we have
|
||||||
// more than 10000 mp-aircrafts in the property tree we should optimize the mp-server
|
// more than 10000 mp-aircrafts in the property tree we should optimize the mp-server
|
||||||
for (i = 0; i < 10000; i++) {
|
for (i = 0; i < 10000; i++) {
|
||||||
p = root->getNode(typeString, i, false);
|
p = root->getNode(static_cast<std::string>(typeString), i, false);
|
||||||
|
|
||||||
if (!p || !p->getBoolValue("valid", false))
|
if (!p || !p->getBoolValue("valid", false))
|
||||||
break;
|
break;
|
||||||
|
@ -443,7 +443,7 @@ FGAIManager::attach(const SGSharedPtr<FGAIBase> &model)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p = root->getNode(typeString, i, true);
|
p = root->getNode(static_cast<std::string>(typeString), i, true);
|
||||||
model->setManager(this, p);
|
model->setManager(this, p);
|
||||||
ai_list.push_back(model);
|
ai_list.push_back(model);
|
||||||
|
|
||||||
|
@ -720,11 +720,11 @@ FGAIManager::calcCollision(double alt, double lat, double lon, double fuse_range
|
||||||
|
|
||||||
while (ai_list_itr != end) {
|
while (ai_list_itr != end) {
|
||||||
double tgt_alt = (*ai_list_itr)->_getAltitude();
|
double tgt_alt = (*ai_list_itr)->_getAltitude();
|
||||||
int type = (*ai_list_itr)->getType();
|
FGAIBase::object_type type = (*ai_list_itr)->getType();
|
||||||
tgt_ht[type] += fuse_range;
|
tgt_ht[static_cast<int>(type)] += fuse_range;
|
||||||
|
|
||||||
if (fabs(tgt_alt - alt) > tgt_ht[type] || type == FGAIBase::otBallistic
|
if (fabs(tgt_alt - alt) > tgt_ht[static_cast<int>(type)] || type == FGAIBase::object_type::otBallistic
|
||||||
|| type == FGAIBase::otStorm || type == FGAIBase::otThermal ) {
|
|| type == FGAIBase::object_type::otStorm || type == FGAIBase::object_type::otThermal ) {
|
||||||
//SG_LOG(SG_AI, SG_DEBUG, "AIManager: skipping "
|
//SG_LOG(SG_AI, SG_DEBUG, "AIManager: skipping "
|
||||||
// << fabs(tgt_alt - alt)
|
// << fabs(tgt_alt - alt)
|
||||||
// << " "
|
// << " "
|
||||||
|
@ -734,7 +734,7 @@ FGAIManager::calcCollision(double alt, double lat, double lon, double fuse_range
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int id = (*ai_list_itr)->getID();
|
int id = (*ai_list_itr)->getID();
|
||||||
|
|
||||||
double range = calcRangeFt(cartPos, (*ai_list_itr));
|
double range = calcRangeFt(cartPos, (*ai_list_itr));
|
||||||
|
|
||||||
|
@ -747,11 +747,11 @@ FGAIManager::calcCollision(double alt, double lat, double lon, double fuse_range
|
||||||
// << " alt " << tgt_alt
|
// << " alt " << tgt_alt
|
||||||
// );
|
// );
|
||||||
|
|
||||||
tgt_length[type] += fuse_range;
|
tgt_length[static_cast<int>(type)] += fuse_range;
|
||||||
|
|
||||||
if (range < tgt_length[type]){
|
if (range < tgt_length[static_cast<int>(type)]){
|
||||||
SG_LOG(SG_AI, SG_DEBUG, "AIManager: HIT! "
|
SG_LOG(SG_AI, SG_DEBUG, "AIManager: HIT! "
|
||||||
<< " type " << type
|
<< " type " << static_cast<int>(type)
|
||||||
<< " ID " << id
|
<< " ID " << id
|
||||||
<< " range " << range
|
<< " range " << range
|
||||||
<< " alt " << tgt_alt
|
<< " alt " << tgt_alt
|
||||||
|
|
|
@ -39,37 +39,14 @@ using std::string;
|
||||||
|
|
||||||
// #define SG_DEBUG SG_ALERT
|
// #define SG_DEBUG SG_ALERT
|
||||||
|
|
||||||
FGAIMultiplayer::FGAIMultiplayer() :
|
FGAIMultiplayer::FGAIMultiplayer() : FGAIBase(object_type::otMultiplayer, fgGetBool("/sim/multiplay/hot", false)),
|
||||||
FGAIBase(otMultiplayer, fgGetBool("/sim/multiplay/hot", false))
|
m_simple_time_enabled(fgGetNode("/sim/time/simple-time/enabled", true)),
|
||||||
|
m_sim_replay_replay_state(fgGetNode("/sim/replay/replay-state", true)),
|
||||||
|
m_sim_replay_time(fgGetNode("/sim/replay/time", true)),
|
||||||
|
mLogRawSpeedMultiplayer(fgGetNode("/sim/replay/log-raw-speed-multiplayer", true))
|
||||||
{
|
{
|
||||||
no_roll = false;
|
no_roll = false;
|
||||||
|
_searchOrder = ModelSearchOrder::PREFER_DATA;
|
||||||
mTimeOffsetSet = false;
|
|
||||||
mAllowExtrapolation = true;
|
|
||||||
mLagAdjustSystemSpeed = 10;
|
|
||||||
mLastTimestamp = 0;
|
|
||||||
lastUpdateTime = 0;
|
|
||||||
playerLag = 0.03;
|
|
||||||
compensateLag = 1;
|
|
||||||
realTime = false;
|
|
||||||
lastTime=0.0;
|
|
||||||
lagPpsAveraged = 1.0;
|
|
||||||
rawLag = 0.0;
|
|
||||||
rawLagMod = 0.0;
|
|
||||||
lagModAveraged = 0.0;
|
|
||||||
_searchOrder = PREFER_DATA;
|
|
||||||
|
|
||||||
m_simple_time_enabled = fgGetNode("/sim/time/simple-time/enabled", true);
|
|
||||||
m_sim_replay_replay_state = fgGetNode("/sim/replay/replay-state", true);
|
|
||||||
m_sim_replay_time = fgGetNode("/sim/replay/time", true);
|
|
||||||
|
|
||||||
m_simple_time_first_time = true;
|
|
||||||
m_simple_time_compensation = 0.0;
|
|
||||||
m_simple_time_recent_packet_time = 0;
|
|
||||||
mLogRawSpeedMultiplayer = fgGetNode("/sim/replay/log-raw-speed-multiplayer", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
FGAIMultiplayer::~FGAIMultiplayer() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FGAIMultiplayer::init(ModelSearchOrder searchOrder)
|
bool FGAIMultiplayer::init(ModelSearchOrder searchOrder)
|
||||||
|
@ -161,9 +138,7 @@ void FGAIMultiplayer::FGAIMultiplayerInterpolate(
|
||||||
ecLinearVel = interpolate((float)tau, prevIt->second.linearVel, nextIt->second.linearVel);
|
ecLinearVel = interpolate((float)tau, prevIt->second.linearVel, nextIt->second.linearVel);
|
||||||
speed = norm(ecLinearVel) * SG_METER_TO_NM * 3600.0;
|
speed = norm(ecLinearVel) * SG_METER_TO_NM * 3600.0;
|
||||||
|
|
||||||
if (prevIt->second.properties.size()
|
if (prevIt->second.properties.size() == nextIt->second.properties.size()) {
|
||||||
== nextIt->second.properties.size())
|
|
||||||
{
|
|
||||||
std::vector<FGPropertyData*>::const_iterator prevPropIt;
|
std::vector<FGPropertyData*>::const_iterator prevPropIt;
|
||||||
std::vector<FGPropertyData*>::const_iterator prevPropItEnd;
|
std::vector<FGPropertyData*>::const_iterator prevPropItEnd;
|
||||||
std::vector<FGPropertyData*>::const_iterator nextPropIt;
|
std::vector<FGPropertyData*>::const_iterator nextPropIt;
|
||||||
|
@ -929,12 +904,14 @@ FGAIMultiplayer::addMotionInfo(FGExternalMotionData& motionInfo,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
void
|
void
|
||||||
FGAIMultiplayer::setDoubleProperty(const std::string& prop, double val)
|
FGAIMultiplayer::setDoubleProperty(const std::string& prop, double val)
|
||||||
{
|
{
|
||||||
SGPropertyNode* pNode = props->getChild(prop.c_str(), true);
|
SGPropertyNode* pNode = props->getChild(prop.c_str(), true);
|
||||||
pNode->setDoubleValue(val);
|
pNode->setDoubleValue(val);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void FGAIMultiplayer::clearMotionInfo()
|
void FGAIMultiplayer::clearMotionInfo()
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,26 +18,31 @@
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
#ifndef _FG_AIMultiplayer_HXX
|
#pragma once
|
||||||
#define _FG_AIMultiplayer_HXX
|
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <MultiPlayer/mpmessages.hxx>
|
#include <MultiPlayer/mpmessages.hxx>
|
||||||
|
|
||||||
#include "AIBase.hxx"
|
#include "AIBase.hxx"
|
||||||
|
|
||||||
class FGAIMultiplayer : public FGAIBase {
|
class FGAIMultiplayer : public FGAIBase {
|
||||||
public:
|
public:
|
||||||
FGAIMultiplayer();
|
FGAIMultiplayer();
|
||||||
virtual ~FGAIMultiplayer();
|
virtual ~FGAIMultiplayer() = default;
|
||||||
|
|
||||||
|
string_view getTypeString(void) const override { return "multiplayer"; }
|
||||||
bool init(ModelSearchOrder searchOrder) override;
|
bool init(ModelSearchOrder searchOrder) override;
|
||||||
void bind() override;
|
void bind() override;
|
||||||
void update(double dt) override;
|
void update(double dt) override;
|
||||||
|
|
||||||
void addMotionInfo(FGExternalMotionData& motionInfo, long stamp);
|
void addMotionInfo(FGExternalMotionData& motionInfo, long stamp);
|
||||||
|
|
||||||
|
#if 0
|
||||||
void setDoubleProperty(const std::string& prop, double val);
|
void setDoubleProperty(const std::string& prop, double val);
|
||||||
|
#endif
|
||||||
|
|
||||||
long getLastTimestamp(void) const
|
long getLastTimestamp(void) const
|
||||||
{
|
{
|
||||||
|
@ -98,11 +103,6 @@ public:
|
||||||
|
|
||||||
void clearMotionInfo();
|
void clearMotionInfo();
|
||||||
|
|
||||||
const char* getTypeString(void) const override
|
|
||||||
{
|
|
||||||
return "multiplayer";
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Automatic sorting of motion data according to its timestamp
|
// Automatic sorting of motion data according to its timestamp
|
||||||
|
@ -141,26 +141,28 @@ private:
|
||||||
SGVec3f& ecLinearVel
|
SGVec3f& ecLinearVel
|
||||||
);
|
);
|
||||||
|
|
||||||
bool mTimeOffsetSet;
|
bool mTimeOffsetSet = false;
|
||||||
bool realTime;
|
bool realTime = false;
|
||||||
int compensateLag;
|
int compensateLag = 1;
|
||||||
double playerLag;
|
double playerLag = 0.03;
|
||||||
double mTimeOffset;
|
double mTimeOffset = 0.0;
|
||||||
double lastUpdateTime;
|
double lastUpdateTime = 0.0;
|
||||||
double lastTime;
|
double lastTime = 0.0;
|
||||||
double lagPpsAveraged;
|
double lagPpsAveraged = 1.0;
|
||||||
double rawLag, rawLagMod, lagModAveraged;
|
double rawLag = 0.0;
|
||||||
|
double rawLagMod = 0.0;
|
||||||
|
double lagModAveraged = 0.0;
|
||||||
|
|
||||||
/// Properties which are for now exposed for testing
|
/// Properties which are for now exposed for testing
|
||||||
bool mAllowExtrapolation;
|
bool mAllowExtrapolation = true;
|
||||||
double mLagAdjustSystemSpeed;
|
double mLagAdjustSystemSpeed = 10.0;
|
||||||
|
|
||||||
long mLastTimestamp;
|
long mLastTimestamp = 0;
|
||||||
|
|
||||||
// Properties for tankers
|
// Properties for tankers
|
||||||
SGPropertyNode_ptr refuel_node;
|
SGPropertyNode_ptr refuel_node;
|
||||||
bool isTanker;
|
bool isTanker = false;
|
||||||
bool contact; // set if this tanker is within fuelling range
|
bool contact = false; // set if this tanker is within fuelling range
|
||||||
|
|
||||||
// velocities/u,v,wbody-fps
|
// velocities/u,v,wbody-fps
|
||||||
SGPropertyNode_ptr _uBodyNode;
|
SGPropertyNode_ptr _uBodyNode;
|
||||||
|
@ -174,11 +176,11 @@ private:
|
||||||
SGPropertyNode_ptr m_sim_replay_replay_state;
|
SGPropertyNode_ptr m_sim_replay_replay_state;
|
||||||
SGPropertyNode_ptr m_sim_replay_time;
|
SGPropertyNode_ptr m_sim_replay_time;
|
||||||
|
|
||||||
bool m_simple_time_first_time;
|
bool m_simple_time_first_time = true;
|
||||||
double m_simple_time_offset;
|
double m_simple_time_offset = 0.0;
|
||||||
double m_simple_time_offset_smoothed;
|
double m_simple_time_offset_smoothed = 0.0;
|
||||||
double m_simple_time_compensation;
|
double m_simple_time_compensation = 0.0;
|
||||||
double m_simple_time_recent_packet_time;
|
double m_simple_time_recent_packet_time = 0.0;
|
||||||
|
|
||||||
SGPropertyNode_ptr m_node_simple_time_latest;
|
SGPropertyNode_ptr m_node_simple_time_latest;
|
||||||
SGPropertyNode_ptr m_node_simple_time_offset;
|
SGPropertyNode_ptr m_node_simple_time_offset;
|
||||||
|
@ -203,5 +205,3 @@ private:
|
||||||
|
|
||||||
SGPropertyNode_ptr m_node_log_multiplayer;
|
SGPropertyNode_ptr m_node_log_multiplayer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _FG_AIMultiplayer_HXX
|
|
||||||
|
|
|
@ -793,7 +793,7 @@ void FGAIShip::ProcessFlightPlan(double dt) {
|
||||||
setWPPos();
|
setWPPos();
|
||||||
object_type type = getType();
|
object_type type = getType();
|
||||||
|
|
||||||
if (type != 10) // TODO: magic number
|
if (type != object_type::otGroundVehicle) // is this correct???
|
||||||
AccelTo(prev->getSpeed());
|
AccelTo(prev->getSpeed());
|
||||||
|
|
||||||
_curr_alt = curr->getAltitude();
|
_curr_alt = curr->getAltitude();
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <simgear/scene/material/mat.hxx>
|
#include <simgear/scene/material/mat.hxx>
|
||||||
|
|
||||||
#include "AIBase.hxx"
|
#include "AIBase.hxx"
|
||||||
|
@ -34,7 +36,7 @@ public:
|
||||||
FGAIShip(object_type ot = object_type::otShip);
|
FGAIShip(object_type ot = object_type::otShip);
|
||||||
virtual ~FGAIShip() = default;
|
virtual ~FGAIShip() = default;
|
||||||
|
|
||||||
const char* getTypeString(void) const override { return "ship"; }
|
string_view getTypeString(void) const override { return "ship"; }
|
||||||
void readFromScenario(SGPropertyNode* scFileNode) override;
|
void readFromScenario(SGPropertyNode* scFileNode) override;
|
||||||
|
|
||||||
bool init(ModelSearchOrder searchOrder) override;
|
bool init(ModelSearchOrder searchOrder) override;
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
#include "AIStatic.hxx"
|
#include "AIStatic.hxx"
|
||||||
|
|
||||||
|
|
||||||
FGAIStatic::FGAIStatic() : FGAIBase(otStatic, false) {
|
FGAIStatic::FGAIStatic() : FGAIBase(object_type::otStatic, false) {
|
||||||
_searchOrder = DATA_ONLY;
|
_searchOrder = ModelSearchOrder::DATA_ONLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,4 +36,3 @@ void FGAIStatic::update(double dt) {
|
||||||
FGAIBase::update(dt);
|
FGAIBase::update(dt);
|
||||||
Transform();
|
Transform();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include "AIManager.hxx"
|
#include "AIManager.hxx"
|
||||||
#include "AIBase.hxx"
|
#include "AIBase.hxx"
|
||||||
|
|
||||||
|
@ -31,6 +33,6 @@ public:
|
||||||
FGAIStatic();
|
FGAIStatic();
|
||||||
virtual ~FGAIStatic() = default;
|
virtual ~FGAIStatic() = default;
|
||||||
|
|
||||||
const char* getTypeString(void) const override { return "static"; }
|
string_view getTypeString(void) const override { return "static"; }
|
||||||
void update(double dt) override;
|
void update(double dt) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,12 +27,10 @@
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Scenery/scenery.hxx>
|
#include <Scenery/scenery.hxx>
|
||||||
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
#include "AIStorm.hxx"
|
#include "AIStorm.hxx"
|
||||||
|
|
||||||
|
|
||||||
FGAIStorm::FGAIStorm() : FGAIBase(otStorm, false)
|
FGAIStorm::FGAIStorm() : FGAIBase(object_type::otStorm, false)
|
||||||
{
|
{
|
||||||
delay = 3.6;
|
delay = 3.6;
|
||||||
subflashes = 1;
|
subflashes = 1;
|
||||||
|
@ -142,4 +140,3 @@ void FGAIStorm::Run(double dt) {
|
||||||
turb_rate_node->setDoubleValue(0.5);
|
turb_rate_node->setDoubleValue(0.5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include "AIManager.hxx"
|
#include "AIManager.hxx"
|
||||||
#include "AIBase.hxx"
|
#include "AIBase.hxx"
|
||||||
|
@ -32,7 +33,7 @@ public:
|
||||||
FGAIStorm();
|
FGAIStorm();
|
||||||
virtual ~FGAIStorm() = default;
|
virtual ~FGAIStorm() = default;
|
||||||
|
|
||||||
const char* getTypeString(void) const override { return "thunderstorm"; }
|
string_view getTypeString(void) const override { return "thunderstorm"; }
|
||||||
void readFromScenario(SGPropertyNode* scFileNode) override;
|
void readFromScenario(SGPropertyNode* scFileNode) override;
|
||||||
void update(double dt) override;
|
void update(double dt) override;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
|
|
||||||
|
|
||||||
FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::string& modelString) : FGAIBaseAircraft(otStatic)
|
FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::string& modelString) : FGAIBaseAircraft(object_type::otStatic)
|
||||||
{
|
{
|
||||||
std::size_t pos = modelString.find("/Aircraft/"); // Only supporting AI models from FGDATA/AI/Aircraft for now
|
std::size_t pos = modelString.find("/Aircraft/"); // Only supporting AI models from FGDATA/AI/Aircraft for now
|
||||||
if(pos != std::string::npos)
|
if(pos != std::string::npos)
|
||||||
|
@ -30,7 +30,7 @@ FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::str
|
||||||
model_path.append("INVALID_PATH");
|
model_path.append("INVALID_PATH");
|
||||||
|
|
||||||
setCallSign(callsign);
|
setCallSign(callsign);
|
||||||
_searchOrder = PREFER_AI;
|
_searchOrder = ModelSearchOrder::PREFER_AI;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAISwiftAircraft::updatePosition(SGGeod& position, SGVec3<double>& orientation, double groundspeed, bool initPos)
|
void FGAISwiftAircraft::updatePosition(SGGeod& position, SGVec3<double>& orientation, double groundspeed, bool initPos)
|
||||||
|
@ -92,4 +92,3 @@ void FGAISwiftAircraft::initProps()
|
||||||
m_transponderCModeNode = _getProps()->getNode("swift/transponder/c-mode", true);
|
m_transponderCModeNode = _getProps()->getNode("swift/transponder/c-mode", true);
|
||||||
m_transponderIdentNode = _getProps()->getNode("swift/transponder/ident", true);
|
m_transponderIdentNode = _getProps()->getNode("swift/transponder/ident", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "AIBaseAircraft.hxx"
|
#include "AIBaseAircraft.hxx"
|
||||||
|
@ -72,10 +73,10 @@ public:
|
||||||
FGAISwiftAircraft(const std::string& callsign, const std::string& modelString);
|
FGAISwiftAircraft(const std::string& callsign, const std::string& modelString);
|
||||||
virtual ~FGAISwiftAircraft() = default;
|
virtual ~FGAISwiftAircraft() = default;
|
||||||
|
|
||||||
const char* getTypeString() const override { return "swift"; }
|
string_view getTypeString() const override { return "swift"; }
|
||||||
|
void update(double dt) override;
|
||||||
|
|
||||||
void updatePosition(SGGeod& position, SGVec3<double>& orientation, double groundspeed, bool initPos);
|
void updatePosition(SGGeod& position, SGVec3<double>& orientation, double groundspeed, bool initPos);
|
||||||
void update(double dt) override;
|
|
||||||
double getGroundElevation(const SGGeod& pos) const;
|
double getGroundElevation(const SGGeod& pos) const;
|
||||||
void initProps();
|
void initProps();
|
||||||
void setPlaneSurface(const AircraftSurfaces& surfaces);
|
void setPlaneSurface(const AircraftSurfaces& surfaces);
|
||||||
|
@ -88,4 +89,3 @@ private:
|
||||||
SGPropertyNode_ptr m_transponderCModeNode;
|
SGPropertyNode_ptr m_transponderCModeNode;
|
||||||
SGPropertyNode_ptr m_transponderIdentNode;
|
SGPropertyNode_ptr m_transponderIdentNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include "AIAircraft.hxx"
|
#include "AIAircraft.hxx"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,7 +40,7 @@ public:
|
||||||
FGAITanker(FGAISchedule* ref = 0);
|
FGAITanker(FGAISchedule* ref = 0);
|
||||||
virtual ~FGAITanker() = default;
|
virtual ~FGAITanker() = default;
|
||||||
|
|
||||||
const char* getTypeString(void) const override { return "tanker"; }
|
string_view getTypeString(void) const override { return "tanker"; }
|
||||||
void readFromScenario(SGPropertyNode* scFileNode) override;
|
void readFromScenario(SGPropertyNode* scFileNode) override;
|
||||||
void bind() override;
|
void bind() override;
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,10 @@
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Scenery/scenery.hxx>
|
#include <Scenery/scenery.hxx>
|
||||||
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
#include "AIThermal.hxx"
|
#include "AIThermal.hxx"
|
||||||
|
|
||||||
|
|
||||||
FGAIThermal::FGAIThermal() : FGAIBase(otThermal, false)
|
FGAIThermal::FGAIThermal() : FGAIBase(object_type::otThermal, false)
|
||||||
{
|
{
|
||||||
altitude_agl_ft = 0.0;
|
altitude_agl_ft = 0.0;
|
||||||
max_strength = 6.0;
|
max_strength = 6.0;
|
||||||
|
@ -359,4 +357,3 @@ strength = Vup;
|
||||||
range = dist_center;
|
range = dist_center;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "AIManager.hxx"
|
#include <string_view>
|
||||||
|
|
||||||
#include "AIBase.hxx"
|
#include "AIBase.hxx"
|
||||||
|
#include "AIManager.hxx"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -34,7 +36,7 @@ public:
|
||||||
FGAIThermal();
|
FGAIThermal();
|
||||||
virtual ~FGAIThermal() = default;
|
virtual ~FGAIThermal() = default;
|
||||||
|
|
||||||
const char* getTypeString(void) const override { return "thermal"; }
|
string_view getTypeString(void) const override { return "thermal"; }
|
||||||
void readFromScenario(SGPropertyNode* scFileNode) override;
|
void readFromScenario(SGPropertyNode* scFileNode) override;
|
||||||
|
|
||||||
bool init(ModelSearchOrder searchOrder) override;
|
bool init(ModelSearchOrder searchOrder) override;
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include "AIWingman.hxx"
|
#include "AIWingman.hxx"
|
||||||
|
|
||||||
FGAIWingman::FGAIWingman() : FGAIBallistic(otWingman),
|
FGAIWingman::FGAIWingman() : FGAIBallistic(object_type::otWingman),
|
||||||
_formate_to_ac(true),
|
_formate_to_ac(true),
|
||||||
_break(false),
|
_break(false),
|
||||||
_join(false),
|
_join(false),
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <simgear/sg_inlines.h>
|
#include <simgear/sg_inlines.h>
|
||||||
|
|
||||||
#include "AIBallistic.hxx"
|
#include "AIBallistic.hxx"
|
||||||
|
@ -31,7 +33,7 @@ public:
|
||||||
FGAIWingman();
|
FGAIWingman();
|
||||||
virtual ~FGAIWingman() = default;
|
virtual ~FGAIWingman() = default;
|
||||||
|
|
||||||
const char* getTypeString(void) const override { return "wingman"; }
|
string_view getTypeString(void) const override { return "wingman"; }
|
||||||
void readFromScenario(SGPropertyNode* scFileNode) override;
|
void readFromScenario(SGPropertyNode* scFileNode) override;
|
||||||
|
|
||||||
bool init(ModelSearchOrder searchOrder) override;
|
bool init(ModelSearchOrder searchOrder) override;
|
||||||
|
|
|
@ -134,7 +134,7 @@ void FGSubmodelMgr::update(double dt)
|
||||||
FGAIBase::object_type object_type =(*sm_list_itr)->getType();
|
FGAIBase::object_type object_type =(*sm_list_itr)->getType();
|
||||||
|
|
||||||
// Continue if object is not ballistic
|
// Continue if object is not ballistic
|
||||||
if (object_type != FGAIBase::otBallistic) {
|
if (object_type != FGAIBase::object_type::otBallistic) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -224,7 +224,7 @@ void FDMShell::update(double dt)
|
||||||
if (_ai_wake_enabled->getBoolValue()) {
|
if (_ai_wake_enabled->getBoolValue()) {
|
||||||
for (FGAIBase* base : _ai_mgr->get_ai_list()) {
|
for (FGAIBase* base : _ai_mgr->get_ai_list()) {
|
||||||
try {
|
try {
|
||||||
if (base->isa(FGAIBase::otAircraft) ) {
|
if (base->isa(FGAIBase::object_type::otAircraft) ) {
|
||||||
SGVec3d pos = _impl->getCartPosition();
|
SGVec3d pos = _impl->getCartPosition();
|
||||||
const SGSharedPtr<FGAIAircraft> aircraft = dynamic_cast<FGAIAircraft*>(base);
|
const SGSharedPtr<FGAIAircraft> aircraft = dynamic_cast<FGAIAircraft*>(base);
|
||||||
double range = _ai_mgr->calcRangeFt(pos, aircraft)*SG_FEET_TO_METER;
|
double range = _ai_mgr->calcRangeFt(pos, aircraft)*SG_FEET_TO_METER;
|
||||||
|
|
|
@ -115,7 +115,7 @@ void AIManagerTests::testAircraftWaypoints()
|
||||||
|
|
||||||
auto ai = aim->addObject(aircraftDefinition);
|
auto ai = aim->addObject(aircraftDefinition);
|
||||||
CPPUNIT_ASSERT(ai);
|
CPPUNIT_ASSERT(ai);
|
||||||
CPPUNIT_ASSERT_EQUAL(FGAIBase::otAircraft, ai->getType());
|
CPPUNIT_ASSERT_EQUAL(FGAIBase::object_type::otAircraft, ai->getType());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string{"aircraft"}, std::string{ai->getTypeString()});
|
CPPUNIT_ASSERT_EQUAL(std::string{"aircraft"}, std::string{ai->getTypeString()});
|
||||||
|
|
||||||
auto aiAircraft = static_cast<FGAIAircraft*>(ai.get());
|
auto aiAircraft = static_cast<FGAIAircraft*>(ai.get());
|
||||||
|
|
Loading…
Add table
Reference in a new issue