Added destructor for Body, removeBody method for PlanetarySystem.
This commit is contained in:
parent
c20240a5e2
commit
0a120acf7e
|
@ -39,6 +39,14 @@ Body::Body(PlanetarySystem* _system) :
|
|||
}
|
||||
|
||||
|
||||
Body::~Body()
|
||||
{
|
||||
// clean up orbit, atmosphere, etc.
|
||||
if (system != NULL)
|
||||
system->removeBody(this);
|
||||
}
|
||||
|
||||
|
||||
PlanetarySystem* Body::getSystem() const
|
||||
{
|
||||
return system;
|
||||
|
@ -341,6 +349,26 @@ PlanetarySystem::PlanetarySystem(const Star* _star) :
|
|||
}
|
||||
|
||||
|
||||
void PlanetarySystem::addBody(Body* body)
|
||||
{
|
||||
satellites.insert(satellites.end(), body);
|
||||
}
|
||||
|
||||
|
||||
void PlanetarySystem::removeBody(Body* body)
|
||||
{
|
||||
for (vector<Body*>::iterator iter = satellites.begin();
|
||||
iter != satellites.end(); iter++)
|
||||
{
|
||||
if (*iter == body)
|
||||
{
|
||||
satellites.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Body* PlanetarySystem::find(string _name, bool deepSearch) const
|
||||
{
|
||||
for (vector<Body*>::const_iterator iter = satellites.begin();
|
||||
|
|
|
@ -31,7 +31,8 @@ class PlanetarySystem
|
|||
Body* getPrimaryBody() const { return primary; };
|
||||
int getSystemSize() const { return satellites.size(); };
|
||||
Body* getBody(int i) const { return satellites[i]; };
|
||||
void addBody(Body* body) { satellites.insert(satellites.end(), body); };
|
||||
void addBody(Body* body);
|
||||
void removeBody(Body* body);
|
||||
|
||||
enum TraversalResult
|
||||
{
|
||||
|
@ -85,6 +86,7 @@ class Body
|
|||
{
|
||||
public:
|
||||
Body(PlanetarySystem*);
|
||||
~Body();
|
||||
|
||||
PlanetarySystem* getSystem() const;
|
||||
std::string getName() const;
|
||||
|
|
Loading…
Reference in a new issue