1
0
Fork 0

David Culp:

I added some things to the AI stuff to improve the AIThermal processing.
Before, all the thermals were processed in order, and the last one overwrote
the prior one.  Now, only the data from the nearest thermal is kept.  This
way a tile can be populated with many thermals, and (as long as they have the
same diameter) the one nearest the airplane correctly takes effect.  This
will make us ready for the next step, "auto-thermaling", where FlightGear's
tile manager can cover a tile with thermals, and set the thermal strength
based on land-use type.

I moved the enumerated object_type to the base class.  When an AI object is
created it now sets the _otype variable in the base class.  This lets the AI
manager find out what kind of AI object it is dealing with, using the base
pointer.  I also added a function isa() to the base class, so the manager can
process objects differently based on their type.

The AI manager now sends AIThermal processing to a different function, where
only the data from the nearest thermal is kept.  After the manager processes
all the AI objects, then the results from the nearest thermal are applied to
wind-from-down.
This commit is contained in:
ehofman 2004-03-07 12:08:46 +00:00
parent 536d135856
commit 6a08c79fcc
10 changed files with 66 additions and 17 deletions

View file

@ -54,11 +54,12 @@ FGAIAircraft *FGAIAircraft::_self = NULL;
FGAIAircraft::FGAIAircraft(FGAIManager* mgr) {
manager = mgr;
_self = this;
_type_str = "aircraft";
_otype = otAircraft;
// set heading and altitude locks
hdg_lock = false;
alt_lock = false;
_type_str = "aircraft";
}

View file

@ -30,6 +30,7 @@
FGAIBallistic::FGAIBallistic(FGAIManager* mgr) {
manager = mgr;
_type_str = "ballistic";
_otype = otBallistic;
}
FGAIBallistic::~FGAIBallistic() {

View file

@ -52,6 +52,7 @@ FGAIBase::FGAIBase() {
x_shift = y_shift = rotation = 0.0;
invisible = true;
model_path = "";
_otype = otNull;
}
FGAIBase::~FGAIBase() {
@ -103,6 +104,12 @@ bool FGAIBase::init() {
return true;
}
bool FGAIBase::isa( object_type otype ) {
if ( otype == _otype ) { return true; }
else { return false; }
}
void FGAIBase::bind() {
props->tie("id", SGRawValuePointer<int>(&id));
props->tie("velocities/true-airspeed-kt", SGRawValuePointer<double>(&speed));

View file

@ -41,6 +41,9 @@ public:
virtual void update(double dt);
inline Point3D GetPos() { return(pos); }
enum object_type { otNull, otAircraft, otShip, otBallistic,
otRocket, otStorm, otThermal };
virtual bool init();
virtual void bind();
virtual void unbind();
@ -103,6 +106,7 @@ protected:
static FGAIBase *_self;
const char *_type_str;
object_type _otype;
public:
@ -129,6 +133,7 @@ public:
static double _getRotation();
static bool _isNight();
bool isa( object_type otype );
};

View file

@ -37,6 +37,7 @@ SG_USING_STD(list);
FGAIManager::FGAIManager() {
initDone = false;
numObjects = 0;
_dt = 0.0;
dt_count = 9;
}
@ -54,6 +55,7 @@ FGAIManager::~FGAIManager() {
void FGAIManager::init() {
int rval;
root = fgGetNode("sim/ai", true);
wind_from_down = fgGetNode("/environment/wind-from-down-fps", true);
for (int i = 0; i < root->nChildren(); i++) {
const SGPropertyNode * entry = root->getChild(i);
@ -128,6 +130,12 @@ void FGAIManager::unbind() {
void FGAIManager::update(double dt) {
// initialize these for finding nearest thermals
range_nearest = 10000.0;
strength = 0.0;
_dt = dt;
ai_list_itr = ai_list.begin();
while(ai_list_itr != ai_list.end()) {
if ((*ai_list_itr)->getDie()) {
@ -138,10 +146,15 @@ void FGAIManager::update(double dt) {
--numObjects;
} else {
fetchUserState();
(*ai_list_itr)->update(dt);
if ((*ai_list_itr)->isa(FGAIBase::otThermal)) {
processThermal((FGAIThermal*)*ai_list_itr);
} else {
(*ai_list_itr)->update(_dt);
}
}
++ai_list_itr;
}
wind_from_down->setDoubleValue( strength );
}
@ -277,7 +290,7 @@ int FGAIManager::createThermal( double latitude, double longitude,
++numObjects;
ai_thermal->setLongitude(longitude);
ai_thermal->setLatitude(latitude);
ai_thermal->setStrength(strength);
ai_thermal->setMaxStrength(strength);
ai_thermal->setDiameter(diameter / 6076.11549);
ai_thermal->init();
ai_thermal->bind();
@ -313,3 +326,13 @@ void FGAIManager::fetchUserState( void ) {
dt_count = 0;
}
}
// only keep the results from the nearest thermal
void FGAIManager::processThermal( FGAIThermal* thermal ) {
thermal->update(_dt);
if ( thermal->_getRange() < range_nearest ) {
range_nearest = thermal->_getRange();
strength = thermal->getStrength();
}
}

View file

@ -29,6 +29,7 @@
#include "AIBase.hxx"
SG_USING_STD(list);
class FGAIThermal;
class FGAIManager : public SGSubsystem
@ -53,8 +54,6 @@ private:
public:
enum object_type { otAircraft, otShip, otBallistic, otRocket, otStorm, otThermal };
FGAIManager();
~FGAIManager();
@ -120,6 +119,7 @@ private:
bool initDone;
int numObjects;
SGPropertyNode* root;
SGPropertyNode* wind_from_down;
double user_latitude;
double user_longitude;
@ -128,9 +128,15 @@ private:
double user_pitch;
double user_yaw;
double user_speed;
double _dt;
int dt_count;
void fetchUserState( void );
// used by thermals
double range_nearest;
double strength;
void processThermal( FGAIThermal* thermal );
};
#endif // _FG_AIMANAGER_HXX

View file

@ -29,9 +29,11 @@
FGAIShip::FGAIShip(FGAIManager* mgr) {
manager = mgr;
_type_str = "ship";
_otype = otShip;
hdg_lock = false;
rudder = 0.0;
_type_str = "ship";
}
FGAIShip::~FGAIShip() {

View file

@ -40,6 +40,7 @@ FGAIStorm::FGAIStorm(FGAIManager* mgr) {
manager = mgr;
_self = this;
_type_str = "thunderstorm";
_otype = otStorm;
}

View file

@ -40,8 +40,10 @@ FGAIThermal::FGAIThermal(FGAIManager* mgr) {
manager = mgr;
_self = this;
_type_str = "thermal";
strength = 6.0;
_otype = otThermal;
max_strength = 6.0;
diameter = 0.5;
strength = factor = 0.0;
}
@ -51,8 +53,7 @@ FGAIThermal::~FGAIThermal() {
bool FGAIThermal::init() {
wind_from_down = fgGetNode("/environment/wind-from-down-fps", true);
scaler = 8.0 * strength / (diameter * diameter * diameter);
factor = 8.0 * max_strength / (diameter * diameter * diameter);
return FGAIBase::init();
}
@ -100,13 +101,13 @@ void FGAIThermal::Run(double dt) {
double range_ft = sqrt( lat_range*lat_range + lon_range*lon_range );
range = range_ft / 6076.11549;
// Set rising air if within range.
// Calculate speed of rising air if within range.
// Air vertical speed is maximum at center of thermal,
// and decreases to zero at the edge (as distance cubed).
if (range < (diameter * 0.5)) {
wind_from_down->setDoubleValue( strength - (range * range * range * scaler) );
strength = max_strength - ( range * range * range * factor );
} else {
wind_from_down->setDoubleValue( 0.0 );
strength = 0.0;
}
}

View file

@ -40,8 +40,10 @@ public:
virtual void unbind();
void update(double dt);
inline void setStrength( double s ) { strength = s; };
inline void setMaxStrength( double s ) { max_strength = s; };
inline void setDiameter( double d ) { diameter = d; };
inline double getStrength() const { return strength; };
inline double getDiameter() const { return diameter; };
protected:
static FGAIThermal *_self;
@ -50,10 +52,10 @@ private:
double dt;
void Run(double dt);
SGPropertyNode* wind_from_down;
double max_strength;
double strength;
double diameter;
double scaler;
double factor;
};