Internally keep track of the number of models per type. This really speeds up searching for the number of submodels of one type.
This commit is contained in:
parent
0d576e1925
commit
af7c5e48be
4 changed files with 23 additions and 22 deletions
|
@ -51,7 +51,7 @@ bool FGAIBallistic::init() {
|
||||||
|
|
||||||
void FGAIBallistic::bind() {
|
void FGAIBallistic::bind() {
|
||||||
// FGAIBase::bind();
|
// FGAIBase::bind();
|
||||||
props->tie("sim/time/elapsed-sec", SGRawValuePointer<double>(&life_timer));
|
props->tie("sim/time/elapsed-sec", SGRawValuePointer<double>(&(this->life_timer)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIBallistic::unbind() {
|
void FGAIBallistic::unbind() {
|
||||||
|
|
|
@ -75,8 +75,9 @@ public:
|
||||||
virtual void update(double dt);
|
virtual void update(double dt);
|
||||||
inline Point3D GetPos() { return(pos); }
|
inline Point3D GetPos() { return(pos); }
|
||||||
|
|
||||||
enum object_type { otNull, otAircraft, otShip, otBallistic,
|
enum object_type { otNull = 0, otAircraft, otShip, otBallistic,
|
||||||
otRocket, otStorm, otThermal };
|
otRocket, otStorm, otThermal,
|
||||||
|
MAX_OBJECTS }; // Needs to be last!!!
|
||||||
|
|
||||||
virtual bool init();
|
virtual bool init();
|
||||||
virtual void bind();
|
virtual void bind();
|
||||||
|
|
|
@ -36,7 +36,8 @@ SG_USING_STD(list);
|
||||||
|
|
||||||
FGAIManager::FGAIManager() {
|
FGAIManager::FGAIManager() {
|
||||||
initDone = false;
|
initDone = false;
|
||||||
numObjects = 0;
|
for (int i=0; i < FGAIBase::MAX_OBJECTS; i++)
|
||||||
|
numObjects[i] = 0;
|
||||||
_dt = 0.0;
|
_dt = 0.0;
|
||||||
dt_count = 9;
|
dt_count = 9;
|
||||||
scenario_filename = "";
|
scenario_filename = "";
|
||||||
|
@ -73,7 +74,7 @@ void FGAIManager::init() {
|
||||||
|
|
||||||
void FGAIManager::bind() {
|
void FGAIManager::bind() {
|
||||||
root = globals->get_props()->getNode("ai/models", true);
|
root = globals->get_props()->getNode("ai/models", true);
|
||||||
root->tie("count", SGRawValuePointer<int>(&numObjects));
|
root->tie("count", SGRawValuePointer<int>(&numObjects[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,7 +99,8 @@ void FGAIManager::update(double dt) {
|
||||||
if ((*ai_list_itr)->getDie()) {
|
if ((*ai_list_itr)->getDie()) {
|
||||||
freeID((*ai_list_itr)->getID());
|
freeID((*ai_list_itr)->getID());
|
||||||
delete (*ai_list_itr);
|
delete (*ai_list_itr);
|
||||||
--numObjects;
|
--numObjects[(*ai_list_itr)->getType()];
|
||||||
|
--numObjects[0];
|
||||||
if ( ai_list_itr == ai_list.begin() ) {
|
if ( ai_list_itr == ai_list.begin() ) {
|
||||||
ai_list.erase(ai_list_itr);
|
ai_list.erase(ai_list_itr);
|
||||||
ai_list_itr = ai_list.begin();
|
ai_list_itr = ai_list.begin();
|
||||||
|
@ -160,7 +162,8 @@ int FGAIManager::createAircraft( FGAIModelEntity *entity ) {
|
||||||
FGAIAircraft* ai_plane = new FGAIAircraft(this);
|
FGAIAircraft* ai_plane = new FGAIAircraft(this);
|
||||||
ai_list.push_back(ai_plane);
|
ai_list.push_back(ai_plane);
|
||||||
ai_plane->setID( assignID() );
|
ai_plane->setID( assignID() );
|
||||||
++numObjects;
|
++numObjects[0];
|
||||||
|
++numObjects[FGAIBase::otAircraft];
|
||||||
if (entity->m_class == "light") {
|
if (entity->m_class == "light") {
|
||||||
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::LIGHT]);
|
ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::LIGHT]);
|
||||||
} else if (entity->m_class == "ww2_fighter") {
|
} else if (entity->m_class == "ww2_fighter") {
|
||||||
|
@ -197,7 +200,8 @@ int FGAIManager::createShip( FGAIModelEntity *entity ) {
|
||||||
FGAIShip* ai_ship = new FGAIShip(this);
|
FGAIShip* ai_ship = new FGAIShip(this);
|
||||||
ai_list.push_back(ai_ship);
|
ai_list.push_back(ai_ship);
|
||||||
ai_ship->setID( assignID() );
|
ai_ship->setID( assignID() );
|
||||||
++numObjects;
|
++numObjects[0];
|
||||||
|
++numObjects[FGAIBase::otShip];
|
||||||
ai_ship->setHeading(entity->heading);
|
ai_ship->setHeading(entity->heading);
|
||||||
ai_ship->setSpeed(entity->speed);
|
ai_ship->setSpeed(entity->speed);
|
||||||
ai_ship->setPath(entity->path);
|
ai_ship->setPath(entity->path);
|
||||||
|
@ -220,7 +224,8 @@ int FGAIManager::createBallistic( FGAIModelEntity *entity ) {
|
||||||
FGAIBallistic* ai_ballistic = new FGAIBallistic(this);
|
FGAIBallistic* ai_ballistic = new FGAIBallistic(this);
|
||||||
ai_list.push_back(ai_ballistic);
|
ai_list.push_back(ai_ballistic);
|
||||||
ai_ballistic->setID( assignID() );
|
ai_ballistic->setID( assignID() );
|
||||||
++numObjects;
|
++numObjects[0];
|
||||||
|
++numObjects[FGAIBase::otBallistic];
|
||||||
ai_ballistic->setAzimuth(entity->azimuth);
|
ai_ballistic->setAzimuth(entity->azimuth);
|
||||||
ai_ballistic->setElevation(entity->elevation);
|
ai_ballistic->setElevation(entity->elevation);
|
||||||
ai_ballistic->setSpeed(entity->speed);
|
ai_ballistic->setSpeed(entity->speed);
|
||||||
|
@ -244,7 +249,8 @@ int FGAIManager::createStorm( FGAIModelEntity *entity ) {
|
||||||
FGAIStorm* ai_storm = new FGAIStorm(this);
|
FGAIStorm* ai_storm = new FGAIStorm(this);
|
||||||
ai_list.push_back(ai_storm);
|
ai_list.push_back(ai_storm);
|
||||||
ai_storm->setID( assignID() );
|
ai_storm->setID( assignID() );
|
||||||
++numObjects;
|
++numObjects[0];
|
||||||
|
++numObjects[FGAIBase::otStorm];
|
||||||
ai_storm->setHeading(entity->heading);
|
ai_storm->setHeading(entity->heading);
|
||||||
ai_storm->setSpeed(entity->speed);
|
ai_storm->setSpeed(entity->speed);
|
||||||
ai_storm->setPath(entity->path);
|
ai_storm->setPath(entity->path);
|
||||||
|
@ -261,7 +267,8 @@ int FGAIManager::createThermal( FGAIModelEntity *entity ) {
|
||||||
FGAIThermal* ai_thermal = new FGAIThermal(this);
|
FGAIThermal* ai_thermal = new FGAIThermal(this);
|
||||||
ai_list.push_back(ai_thermal);
|
ai_list.push_back(ai_thermal);
|
||||||
ai_thermal->setID( assignID() );
|
ai_thermal->setID( assignID() );
|
||||||
++numObjects;
|
++numObjects[0];
|
||||||
|
++numObjects[FGAIBase::otThermal];
|
||||||
ai_thermal->setLongitude(entity->longitude);
|
ai_thermal->setLongitude(entity->longitude);
|
||||||
ai_thermal->setLatitude(entity->latitude);
|
ai_thermal->setLatitude(entity->latitude);
|
||||||
ai_thermal->setMaxStrength(entity->strength);
|
ai_thermal->setMaxStrength(entity->strength);
|
||||||
|
@ -276,10 +283,11 @@ void FGAIManager::destroyObject( int ID ) {
|
||||||
while(ai_list_itr != ai_list.end()) {
|
while(ai_list_itr != ai_list.end()) {
|
||||||
if ((*ai_list_itr)->getID() == ID) {
|
if ((*ai_list_itr)->getID() == ID) {
|
||||||
freeID( ID );
|
freeID( ID );
|
||||||
|
--numObjects[0];
|
||||||
|
--numObjects[(*ai_list_itr)->getType()];
|
||||||
delete (*ai_list_itr);
|
delete (*ai_list_itr);
|
||||||
ai_list.erase(ai_list_itr);
|
ai_list.erase(ai_list_itr);
|
||||||
--ai_list_itr;
|
--ai_list_itr;
|
||||||
--numObjects;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
++ai_list_itr;
|
++ai_list_itr;
|
||||||
|
@ -346,14 +354,6 @@ void FGAIManager::processScenario( string filename ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int FGAIManager::getNum( FGAIBase::object_type ot ) {
|
int FGAIManager::getNum( FGAIBase::object_type ot ) {
|
||||||
ai_list_iterator itr = ai_list.begin();
|
return numObjects[ot];
|
||||||
int count = 0;
|
|
||||||
while(itr != ai_list.end()) {
|
|
||||||
if ((*itr)->getType() == ot) {
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
++itr;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ private:
|
||||||
|
|
||||||
bool initDone;
|
bool initDone;
|
||||||
bool enabled;
|
bool enabled;
|
||||||
int numObjects;
|
int numObjects[FGAIBase::MAX_OBJECTS];
|
||||||
SGPropertyNode* root;
|
SGPropertyNode* root;
|
||||||
SGPropertyNode* wind_from_down_node;
|
SGPropertyNode* wind_from_down_node;
|
||||||
string scenario_filename;
|
string scenario_filename;
|
||||||
|
|
Loading…
Add table
Reference in a new issue