diff --git a/src/AIModel/AIBallistic.cxx b/src/AIModel/AIBallistic.cxx index 781f2ffd4..ddac65cdf 100644 --- a/src/AIModel/AIBallistic.cxx +++ b/src/AIModel/AIBallistic.cxx @@ -51,7 +51,7 @@ bool FGAIBallistic::init() { void FGAIBallistic::bind() { // FGAIBase::bind(); - props->tie("sim/time/elapsed-sec", SGRawValuePointer(&life_timer)); + props->tie("sim/time/elapsed-sec", SGRawValuePointer(&(this->life_timer))); } void FGAIBallistic::unbind() { diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 51ad35db5..90c3a4b6d 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -75,8 +75,9 @@ public: virtual void update(double dt); inline Point3D GetPos() { return(pos); } - enum object_type { otNull, otAircraft, otShip, otBallistic, - otRocket, otStorm, otThermal }; + enum object_type { otNull = 0, otAircraft, otShip, otBallistic, + otRocket, otStorm, otThermal, + MAX_OBJECTS }; // Needs to be last!!! virtual bool init(); virtual void bind(); diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 3cc50714a..0c8b1c028 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -36,7 +36,8 @@ SG_USING_STD(list); FGAIManager::FGAIManager() { initDone = false; - numObjects = 0; + for (int i=0; i < FGAIBase::MAX_OBJECTS; i++) + numObjects[i] = 0; _dt = 0.0; dt_count = 9; scenario_filename = ""; @@ -73,7 +74,7 @@ void FGAIManager::init() { void FGAIManager::bind() { root = globals->get_props()->getNode("ai/models", true); - root->tie("count", SGRawValuePointer(&numObjects)); + root->tie("count", SGRawValuePointer(&numObjects[0])); } @@ -98,7 +99,8 @@ void FGAIManager::update(double dt) { if ((*ai_list_itr)->getDie()) { freeID((*ai_list_itr)->getID()); delete (*ai_list_itr); - --numObjects; + --numObjects[(*ai_list_itr)->getType()]; + --numObjects[0]; if ( ai_list_itr == ai_list.begin() ) { ai_list.erase(ai_list_itr); ai_list_itr = ai_list.begin(); @@ -160,7 +162,8 @@ int FGAIManager::createAircraft( FGAIModelEntity *entity ) { FGAIAircraft* ai_plane = new FGAIAircraft(this); ai_list.push_back(ai_plane); ai_plane->setID( assignID() ); - ++numObjects; + ++numObjects[0]; + ++numObjects[FGAIBase::otAircraft]; if (entity->m_class == "light") { ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::LIGHT]); } else if (entity->m_class == "ww2_fighter") { @@ -197,7 +200,8 @@ int FGAIManager::createShip( FGAIModelEntity *entity ) { FGAIShip* ai_ship = new FGAIShip(this); ai_list.push_back(ai_ship); ai_ship->setID( assignID() ); - ++numObjects; + ++numObjects[0]; + ++numObjects[FGAIBase::otShip]; ai_ship->setHeading(entity->heading); ai_ship->setSpeed(entity->speed); ai_ship->setPath(entity->path); @@ -220,7 +224,8 @@ int FGAIManager::createBallistic( FGAIModelEntity *entity ) { FGAIBallistic* ai_ballistic = new FGAIBallistic(this); ai_list.push_back(ai_ballistic); ai_ballistic->setID( assignID() ); - ++numObjects; + ++numObjects[0]; + ++numObjects[FGAIBase::otBallistic]; ai_ballistic->setAzimuth(entity->azimuth); ai_ballistic->setElevation(entity->elevation); ai_ballistic->setSpeed(entity->speed); @@ -244,7 +249,8 @@ int FGAIManager::createStorm( FGAIModelEntity *entity ) { FGAIStorm* ai_storm = new FGAIStorm(this); ai_list.push_back(ai_storm); ai_storm->setID( assignID() ); - ++numObjects; + ++numObjects[0]; + ++numObjects[FGAIBase::otStorm]; ai_storm->setHeading(entity->heading); ai_storm->setSpeed(entity->speed); ai_storm->setPath(entity->path); @@ -261,7 +267,8 @@ int FGAIManager::createThermal( FGAIModelEntity *entity ) { FGAIThermal* ai_thermal = new FGAIThermal(this); ai_list.push_back(ai_thermal); ai_thermal->setID( assignID() ); - ++numObjects; + ++numObjects[0]; + ++numObjects[FGAIBase::otThermal]; ai_thermal->setLongitude(entity->longitude); ai_thermal->setLatitude(entity->latitude); ai_thermal->setMaxStrength(entity->strength); @@ -276,10 +283,11 @@ void FGAIManager::destroyObject( int ID ) { while(ai_list_itr != ai_list.end()) { if ((*ai_list_itr)->getID() == ID) { freeID( ID ); + --numObjects[0]; + --numObjects[(*ai_list_itr)->getType()]; delete (*ai_list_itr); ai_list.erase(ai_list_itr); --ai_list_itr; - --numObjects; return; } ++ai_list_itr; @@ -346,14 +354,6 @@ void FGAIManager::processScenario( string filename ) { } int FGAIManager::getNum( FGAIBase::object_type ot ) { - ai_list_iterator itr = ai_list.begin(); - int count = 0; - while(itr != ai_list.end()) { - if ((*itr)->getType() == ot) { - ++count; - } - ++itr; - } - return count; + return numObjects[ot]; } diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx index 8433b7ab0..560e82e79 100644 --- a/src/AIModel/AIManager.hxx +++ b/src/AIModel/AIManager.hxx @@ -93,7 +93,7 @@ private: bool initDone; bool enabled; - int numObjects; + int numObjects[FGAIBase::MAX_OBJECTS]; SGPropertyNode* root; SGPropertyNode* wind_from_down_node; string scenario_filename;