1
0
Fork 0

std:: namespace fixes, AIBase cleanup.

Make data members in AIBase protected, and move FGAIModelData to be
a private helper in the .cxx file.
This commit is contained in:
James Turner 2013-03-28 16:49:52 +00:00
parent c2546a431d
commit a7e4f2a971
18 changed files with 107 additions and 97 deletions

View file

@ -52,7 +52,7 @@ public:
void initializeFlightPlan();
FGAIFlightPlan* GetFlightPlan() const { return fp; };
void ProcessFlightPlan( double dt, time_t now );
time_t checkForArrivalTime(const string& wptName);
time_t checkForArrivalTime(const std::string& wptName);
void AccelTo(double speed);
void PitchTo(double angle);

View file

@ -35,6 +35,7 @@
#include <Environment/gravity.hxx>
using namespace simgear;
using std::string;
const double FGAIBallistic::slugs_to_kgs = 14.5939029372;
const double FGAIBallistic::slugs_to_lbs = 32.1740485564;
@ -505,7 +506,7 @@ bool FGAIBallistic::getHtAGL(double start){
_ht_agl_ft = pos.getElevationFt() - _elevation_m * SG_METER_TO_FEET;
if (material) {
const vector<string>& names = material->get_names();
const std::vector<string>& names = material->get_names();
_solid = material->get_solid();
_load_resistance = material->get_load_resistance();
_frictionFactor = material->get_friction_factor();

View file

@ -31,9 +31,6 @@
#include "AIManager.hxx"
#include "AIBase.hxx"
using std::vector;
using std::list;
class FGAIBallistic : public FGAIBase {
public:
@ -72,15 +69,15 @@ public:
void setCollision(bool c);
void setExpiry(bool e);
void setImpact(bool i);
void setImpactReportNode(const string&);
void setImpactReportNode(const std::string&);
void setContentsNode(const SGPropertyNode_ptr);
void setFuseRange(double f);
void setSMPath(const string&);
void setSMPath(const std::string&);
void setSubID(int i);
void setSubmodel(const string&);
void setSubmodel(const std::string&);
void setExternalForce( bool f );
void setForcePath(const string&);
void setContentsPath(const string&);
void setForcePath(const std::string&);
void setContentsPath(const std::string&);
void setForceStabilisation( bool val );
void setGroundOffset(double g);
void setLoadOffset(double l);
@ -188,7 +185,7 @@ private:
bool _slave_load_to_ac;// if true, object will be slaved to the parent ac pos
double _contents_lb; // contents of the object
double _weight_lb; // weight of the object (no contents if appropriate) (lbs)
string _mat_name;
std::string _mat_name;
bool _report_collision; // if true a collision point with AI Objects is calculated
bool _report_impact; // if true an impact point on the terrain is calculated
@ -215,9 +212,9 @@ private:
double _dt_count;
double _next_run;
string _submodel;
string _force_path;
string _contents_path;
std::string _submodel;
std::string _force_path;
std::string _contents_path;
void handle_collision();
void handle_expiry();

View file

@ -53,8 +53,52 @@ const char *default_model = "Models/Geometry/glider.ac";
const double FGAIBase::e = 2.71828183;
const double FGAIBase::lbs_to_slugs = 0.031080950172; //conversion factor
using std::string;
using namespace simgear;
class FGAIModelData : public simgear::SGModelData {
public:
FGAIModelData(SGPropertyNode *root = NULL)
: _nasal( new FGNasalModelDataProxy(root) ),
_ready(false),
_initialized(false)
{
}
~FGAIModelData()
{
}
/** osg callback, thread-safe */
void modelLoaded(const std::string& path, SGPropertyNode *prop, osg::Node *n)
{
// WARNING: Called in a separate OSG thread! Only use thread-safe stuff here...
if (_ready)
return;
_fxpath = prop->getStringValue("sound/path");
_nasal->modelLoaded(path, prop, n);
_ready = true;
}
/** init hook to be called after model is loaded.
* Not thread-safe. Call from main thread only. */
void init(void) { _initialized = true; }
bool needInitilization(void) { return _ready && !_initialized;}
bool isInitialized(void) { return _initialized;}
inline std::string& get_sound_path() { return _fxpath;}
private:
std::auto_ptr<FGNasalModelDataProxy> _nasal;
std::string _fxpath;
bool _ready;
bool _initialized;
};
FGAIBase::FGAIBase(object_type ot, bool enableHot) :
_max_speed(300),
_name(""),
@ -843,27 +887,4 @@ int FGAIBase::_newAIModelID() {
}
FGAIModelData::FGAIModelData(SGPropertyNode *root)
: _nasal( new FGNasalModelDataProxy(root) ),
_ready(false),
_initialized(false)
{
}
FGAIModelData::~FGAIModelData()
{
delete _nasal;
_nasal = NULL;
}
void FGAIModelData::modelLoaded(const string& path, SGPropertyNode *prop, osg::Node *n)
{
// WARNING: Called in a separate OSG thread! Only use thread-safe stuff here...
if (_ready)
return;
_fxpath = prop->getStringValue("sound/path");
_nasal->modelLoaded(path, prop, n);
_ready = true;
}

View file

@ -22,9 +22,10 @@
#include <string>
#include <osg/LOD>
#include <simgear/constants.h>
#include <simgear/scene/model/placement.hxx>
#include <simgear/scene/model/modellib.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/structure/SGReferenced.hxx>
@ -35,16 +36,12 @@
#include <Main/fg_props.hxx>
using std::string;
namespace simgear {
class BVHMaterial;
}
class FGAIManager;
class FGAIFlightPlan;
class FGFX;
class FGNasalModelDataProxy;
class FGAIModelData; // defined below
@ -71,8 +68,8 @@ public:
void updateLOD();
void setManager(FGAIManager* mgr, SGPropertyNode* p);
void setPath( const char* model );
void setSMPath( const string& p );
void setCallSign(const string& );
void setSMPath( const std::string& p );
void setCallSign(const std::string& );
void setSpeed( double speed_KTAS );
void setAltitude( double altitude_ft );
void setAltitudeAGL( double altitude_agl_ft );
@ -95,8 +92,8 @@ public:
void setImpactLat( double lat );
void setImpactLon( double lon );
void setImpactElev( double e );
void setParentName(const string& p);
void setName(const string& n);
void setParentName(const std::string& p);
void setName(const std::string& n);
void setMaxSpeed(double kts);
void calcRangeBearing(double lat, double lon, double lat2, double lon2,
@ -118,29 +115,31 @@ public:
bool getGroundElevationM(const SGGeod& pos, double& elev,
const simgear::BVHMaterial** material) const;
double _elevation_m;
double _getCartPosX() const;
double _getCartPosY() const;
double _getCartPosZ() const;
protected:
double _elevation_m;
double _x_offset;
double _y_offset;
double _z_offset;
double _pitch_offset;
double _roll_offset;
double _yaw_offset;
double _max_speed;
string _path;
string _callsign;
string _submodel;
std::string _path;
std::string _callsign;
std::string _submodel;
std::string _name;
string _parent;
protected:
std::string _parent;
/**
* Tied-properties helper, record nodes which are tied for easy un-tie-ing
*/
@ -195,7 +194,7 @@ protected:
double rotation; // value used by radar display instrument
double ht_diff; // value used by radar display instrument
string model_path; //Path to the 3D model
std::string model_path; //Path to the 3D model
SGModelPlacement aip;
bool delete_me;
@ -318,7 +317,7 @@ public:
static bool _isNight();
string & getCallSign();
std::string & getCallSign();
};
inline void FGAIBase::setManager(FGAIManager* mgr, SGPropertyNode* p) {
@ -330,7 +329,7 @@ inline void FGAIBase::setPath(const char* model ) {
model_path.append(model);
}
inline void FGAIBase::setSMPath(const string& p) {
inline void FGAIBase::setSMPath(const std::string& p) {
_path = p;
}
@ -376,10 +375,10 @@ inline void FGAIBase::setLatitude ( double latitude ) {
pos.setLatitudeDeg( latitude );
}
inline void FGAIBase::setCallSign(const string& s) {
inline void FGAIBase::setCallSign(const std::string& s) {
_callsign = s;
}
inline string& FGAIBase::getCallSign() {
inline std::string& FGAIBase::getCallSign() {
return _callsign;
}
@ -407,11 +406,11 @@ inline void FGAIBase::setYawoffset(double y) {
_yaw_offset = y;
}
inline void FGAIBase::setParentName(const string& p) {
inline void FGAIBase::setParentName(const std::string& p) {
_parent = p;
}
inline void FGAIBase::setName(const string& n) {
inline void FGAIBase::setName(const std::string& n) {
_name = n;
}
@ -453,27 +452,4 @@ inline void FGAIBase::setMaxSpeed(double m) {
}
class FGAIModelData : public simgear::SGModelData {
public:
FGAIModelData(SGPropertyNode *root = 0);
~FGAIModelData();
/** osg callback, thread-safe */
void modelLoaded(const string& path, SGPropertyNode *prop, osg::Node *n);
/** init hook to be called after model is loaded.
* Not thread-safe. Call from main thread only. */
void init(void) { _initialized = true; }
bool needInitilization(void) { return _ready && !_initialized;}
bool isInitialized(void) { return _initialized;}
inline std::string& get_sound_path() { return _fxpath;}
private:
FGNasalModelDataProxy *_nasal;
std::string _fxpath;
bool _ready;
bool _initialized;
};
#endif // _FG_AIBASE_HXX

View file

@ -45,6 +45,7 @@
#include "AIAircraft.hxx"
using std::cerr;
using std::string;
FGAIWaypoint::FGAIWaypoint() {
speed = 0;

View file

@ -41,6 +41,7 @@
#include <FDM/LaRCsim/basic_aero.h>
#include <Navaids/navrecord.hxx>
using std::string;
/* FGAIFlightPlan::create()
* dynamically create a flight plan for AI traffic, based on data provided by the

View file

@ -38,6 +38,7 @@
#include "performancedata.hxx"
using std::iostream;
using std::string;
/*
void FGAIFlightPlan::evaluateRoutePart(double deplat,

View file

@ -38,6 +38,7 @@
#include "AIAircraft.hxx"
#include "performancedata.hxx"
using std::string;
// TODO: Use James Turner's createOnGround functions.
bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac,

View file

@ -30,6 +30,8 @@
#include "AIGroundVehicle.hxx"
using std::string;
FGAIGroundVehicle::FGAIGroundVehicle() :
FGAIShip(otGroundVehicle),

View file

@ -29,6 +29,7 @@
#include "AIMultiplayer.hxx"
using std::string;
// #define SG_DEBUG SG_ALERT

View file

@ -40,6 +40,7 @@
#include "AIShip.hxx"
using std::string;
FGAIShip::FGAIShip(object_type ot) :
// allow HOT to be enabled

View file

@ -52,9 +52,9 @@ public:
void YawTo(double angle);
void ClimbTo(double altitude);
void TurnTo(double heading);
void setCurrName(const string&);
void setNextName(const string&);
void setPrevName(const string&);
void setCurrName(const std::string&);
void setNextName(const std::string&);
void setPrevName(const std::string&);
void setLeadAngleGain(double g);
void setLeadAngleLimit(double l);
void setLeadAngleProp(double p);
@ -99,8 +99,8 @@ private:
void setServiceable(bool s);
void Run(double dt);
void setStartTime(const string&);
void setUntilTime(const string&);
void setStartTime(const std::string&);
void setUntilTime(const std::string&);
//void setWPPos();
void setWPAlt();
void setXTrackError();
@ -110,7 +110,7 @@ private:
double getRange(double lat, double lon, double lat2, double lon2) const;
double getCourse(double lat, double lon, double lat2, double lon2) const;
double getDaySeconds();
double processTimeString(const string& time);
double processTimeString(const std::string& time);
bool initFlightPlan();
bool advanceFlightPlan (double elapsed_sec, double day_sec);
@ -129,9 +129,9 @@ private:
double _xtrack_error;
double _curr_alt, _prev_alt;
string _prev_name, _curr_name, _next_name;
string _path;
string _start_time, _until_time;
std::string _prev_name, _curr_name, _next_name;
std::string _path;
std::string _start_time, _until_time;
bool _repeat;
bool _fp_init;

View file

@ -25,6 +25,8 @@
#include "AITanker.hxx"
using std::string;
FGAITanker::FGAITanker(FGAISchedule* ref): FGAIAircraft(ref){
}

View file

@ -44,10 +44,10 @@ public:
virtual const char* getTypeString(void) const { return "tanker"; }
void setTACANChannelID(const string& id);
void setTACANChannelID(const std::string& id);
private:
string TACAN_channel_id; // The TACAN channel of this tanker
std::string TACAN_channel_id; // The TACAN channel of this tanker
bool contact; // set if this tanker is within fuelling range
virtual void Run(double dt);

View file

@ -25,6 +25,8 @@
using std::cout;
using std::endl;
using std::string;
using std::vector;
const double FGSubmodelMgr::lbs_to_slugs = 0.031080950172;

View file

@ -32,6 +32,8 @@
#include "atc_mgr.hxx"
using std::string;
FGATCManager::FGATCManager() {
controller = 0;
prevController = 0;

View file

@ -37,6 +37,7 @@
#include <AIModel/AIManager.hxx>
using std::endl;
using std::string;
namespace flightgear
{