1
0
Fork 0

Maik Justus,

Here is a patch for two bugs in the AI/multiplayer part:

1. Cannot find model file *.ac error message (was only a false message,
anything worked correctly, the model was loaded from the correct path
afterwards).

2. Often many multiplayer aircrafts are missing in the property-tree.
(but I need them for aerotowing). There is still another bug: The
property in some circumstances seems not to be cleaned up after logout
of a multiplayer. I have added a workaround for this, but I don't now,
if it 100% works (should have no side effects, just aerotow would not
work sometimes). For testing I need more traffic on the mp-server.
This commit is contained in:
durk 2007-01-13 09:04:07 +00:00
parent d0bbe1f45d
commit 7299699903
6 changed files with 100 additions and 26 deletions

View file

@ -120,7 +120,7 @@ void FGAIAircraft::readFromScenario(SGPropertyNode* scFileNode) {
bool FGAIAircraft::init() { bool FGAIAircraft::init() {
//refuel_node = fgGetNode("systems/refuel/contact", true); //refuel_node = fgGetNode("systems/refuel/contact", true);
return FGAIBase::init(); return FGAIBase::init(true);
} }
@ -647,7 +647,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
no_roll = prev->on_ground; no_roll = prev->on_ground;
if (no_roll) { if (no_roll) {
Transform(); // make sure aip is initialized. Transform(); // make sure aip is initialized.
getGroundElev(60.1); // make sure it's exectuted first time around, so force a large dt value getGroundElev(60.1); // make sure it's executed first time around, so force a large dt value
doGroundAltitude(); doGroundAltitude();
} }
// Make sure to announce the aircraft's position // Make sure to announce the aircraft's position
@ -655,16 +655,19 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
prevSpeed = 0; prevSpeed = 0;
return; return;
} // end of initialization } // end of initialization
///////////////////////////////////////////////////////////////////////////
// Check Execution time (currently once every 100 ms)
// Add a bit of randomization to prevent the execution of all flight plans
// in synchrony, which can add significant periodic framerate flutter.
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Check Execution time (currently once every 100 ms double rand_exec_time = (rand() % 100) / 100;
/////////////////////////////////////////////////////////////////////////// if ((dt_count < (0.1+rand_exec_time)) || (now < fp->getStartTime())) {
if ((dt_count < 0.1) || (now < fp->getStartTime())) {
//cerr << "done fp dt" << endl; //cerr << "done fp dt" << endl;
return; return;
} else { } else {
dt_count = 0; dt_count = 0;
} }
// check to see if we've reached the lead point for our next turn // check to see if we've reached the lead point for our next turn
double dist_to_go = fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr); double dist_to_go = fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);

View file

@ -125,27 +125,28 @@ void FGAIBase::Transform() {
} }
} }
bool FGAIBase::init(bool search_in_AI_path) {
bool FGAIBase::init() { if (!model_path.empty()) {
if ( (search_in_AI_path)
if (!model_path.empty()) { &&(model_path.substr(model_path.size() - 4, 4) == ".xml")) {
SGPath ai_path("AI"); SGPath ai_path("AI");
ai_path.append(model_path); ai_path.append(model_path);
try { try {
model = load3DModel( globals->get_fg_root(), ai_path.str(), props, model = load3DModel( globals->get_fg_root(), ai_path.str(), props,
globals->get_sim_time_sec() ); globals->get_sim_time_sec() );
} catch (const sg_exception &) { } catch (const sg_exception &e) {
model = NULL; model = NULL;
} }
} else model = NULL;
if (!model) { if (!model) {
try { try {
model = load3DModel( globals->get_fg_root(), model_path, props, model = load3DModel( globals->get_fg_root(), model_path, props,
globals->get_sim_time_sec() ); globals->get_sim_time_sec() );
} catch (const sg_exception &) { } catch (const sg_exception &e) {
model = NULL; model = NULL;
} }
} }
} }
if (model.get()) { if (model.get()) {
aip.init( model.get() ); aip.init( model.get() );
aip.setVisible(true); aip.setVisible(true);
@ -161,7 +162,6 @@ bool FGAIBase::init() {
} }
setDie(false); setDie(false);
return true; return true;
} }
@ -207,6 +207,19 @@ void FGAIBase::bind() {
&FGAIBase::_getLongitude, &FGAIBase::_getLongitude,
&FGAIBase::_setLongitude)); &FGAIBase::_setLongitude));
props->tie("position/global-x",
SGRawValueMethods<FGAIBase,double>(*this,
&FGAIBase::_getCartPosX,
0));
props->tie("position/global-y",
SGRawValueMethods<FGAIBase,double>(*this,
&FGAIBase::_getCartPosY,
0));
props->tie("position/global-z",
SGRawValueMethods<FGAIBase,double>(*this,
&FGAIBase::_getCartPosZ,
0));
props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch)); props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch));
props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll)); props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll));
props->tie("orientation/true-heading-deg", SGRawValuePointer<double>(&hdg)); props->tie("orientation/true-heading-deg", SGRawValuePointer<double>(&hdg));
@ -248,6 +261,9 @@ void FGAIBase::unbind() {
props->untie("position/altitude-ft"); props->untie("position/altitude-ft");
props->untie("position/latitude-deg"); props->untie("position/latitude-deg");
props->untie("position/longitude-deg"); props->untie("position/longitude-deg");
props->untie("position/global-x");
props->untie("position/global-y");
props->untie("position/global-z");
props->untie("orientation/pitch-deg"); props->untie("orientation/pitch-deg");
props->untie("orientation/roll-deg"); props->untie("orientation/roll-deg");
@ -386,6 +402,42 @@ FGAIBase::getCartPosAt(const SGVec3d& _off) const
return cartPos + off; return cartPos + off;
} }
SGVec3d
FGAIBase::getCartPos() const
{
// Transform that one to the horizontal local coordinate system.
SGQuatd hlTrans = SGQuatd::fromLonLat(pos);
// and postrotate the orientation of the AIModel wrt the horizontal
// local frame
hlTrans *= SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
SGVec3d cartPos = SGVec3d::fromGeod(pos);
return cartPos;
}
double
FGAIBase::_getCartPosX() const
{
SGVec3d cartPos = getCartPos();
return cartPos.x();
}
double
FGAIBase::_getCartPosY() const
{
SGVec3d cartPos = getCartPos();
return cartPos.y();
}
double
FGAIBase::_getCartPosZ() const
{
SGVec3d cartPos = getCartPos();
return cartPos.z();
}
/* /*
* getters and Setters * getters and Setters
*/ */

View file

@ -51,7 +51,7 @@ public:
virtual void readFromScenario(SGPropertyNode* scFileNode); virtual void readFromScenario(SGPropertyNode* scFileNode);
virtual bool init(); virtual bool init(bool search_in_AI_path=false);
virtual void update(double dt); virtual void update(double dt);
virtual void bind(); virtual void bind();
virtual void unbind(); virtual void unbind();
@ -76,6 +76,10 @@ public:
bool getDie(); bool getDie();
SGVec3d getCartPosAt(const SGVec3d& off) const; SGVec3d getCartPosAt(const SGVec3d& off) const;
SGVec3d getCartPos() const;
double _getCartPosX() const;
double _getCartPosY() const;
double _getCartPosZ() const;
protected: protected:

View file

@ -136,12 +136,27 @@ FGAIManager::attach(SGSharedPtr<FGAIBase> model)
unsigned idx = mNumAiTypeModels[model->getType()]; unsigned idx = mNumAiTypeModels[model->getType()];
const char* typeString = model->getTypeString(); const char* typeString = model->getTypeString();
SGPropertyNode* root = globals->get_props()->getNode("ai/models", true); SGPropertyNode* root = globals->get_props()->getNode("ai/models", true);
SGPropertyNode* p = root->getNode(typeString, idx, true); SGPropertyNode* p;
int i;
for (i=0;i<10000;i++) //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
{
p = root->getNode(typeString, i, false);
if (!p) break;
if (p->getIntValue("id",-1)==model->getID())
{
p->setStringValue("callsign","***invalid node***"); //debug only, should never set!
}
}
p = root->getNode(typeString, i, true);
model->setManager(this, p); model->setManager(this, p);
ai_list.push_back(model); ai_list.push_back(model);
++mNumAiModels; ++mNumAiModels;
++(mNumAiTypeModels[model->getType()]); ++(mNumAiTypeModels[model->getType()]);
model->init(); model->init(model->getType()==FGAIBase::otAircraft
|| model->getType()==FGAIBase::otMultiplayer
|| model->getType()==FGAIBase::otStatic);
model->bind(); model->bind();
} }

View file

@ -57,7 +57,7 @@ bool FGAIMultiplayer::init() {
isTanker = true; isTanker = true;
// cout << "isTanker " << isTanker << " " << mCallSign <<endl; // cout << "isTanker " << isTanker << " " << mCallSign <<endl;
} }
return FGAIBase::init(); return FGAIBase::init(true);
} }
void FGAIMultiplayer::bind() { void FGAIMultiplayer::bind() {

View file

@ -42,7 +42,7 @@ FGAIStatic::~FGAIStatic() {
} }
bool FGAIStatic::init() { bool FGAIStatic::init() {
return FGAIBase::init(); return FGAIBase::init(true);
} }
void FGAIStatic::bind() { void FGAIStatic::bind() {