Skip to content

Commit

Permalink
Fix gravpoint mass summation pass
Browse files Browse the repository at this point in the history
- Gravpoint masses must be summed from their children before iterating the child bodies, because child bodies depend on the gravpoint mass to calculate their orbital period
  • Loading branch information
sturnclaw committed Mar 13, 2024
1 parent 3ff5a91 commit a509330
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/galaxy/StarSystemGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,26 +391,28 @@ void StarSystemCustomGenerator::CustomGetKidsOf(RefCountedPtr<StarSystem::Genera
PROFILE_SCOPED()

// gravpoints have no mass, but we sum the masses of its children instead
if (parent->GetType() == SystemBody::TYPE_GRAVPOINT)
if (parent->GetType() == SystemBody::TYPE_GRAVPOINT) {
parent->m_mass = fixed(0);

// parent gravpoint mass = sum of masses of its children
for (const auto *child : children) {
if (child->bodyData.m_type > SystemBody::TYPE_GRAVPOINT && child->bodyData.m_type <= SystemBody::TYPE_STAR_MAX)
parent->m_mass += child->bodyData.m_mass;
else
parent->m_mass += child->bodyData.m_mass / SUN_MASS_TO_EARTH_MASS;
}
}

for (std::vector<CustomSystemBody *>::const_iterator i = children.begin(); i != children.end(); ++i) {
const CustomSystemBody *csbody = *i;

SystemBody *kid = system->NewBody();
kid->m_parent = parent;
kid->m_isCustomBody = true;

// Copy all system body parameters from the custom system body
*kid = csbody->bodyData;

// parent gravpoint mass = sum of masses of its children
if (parent->GetType() == SystemBody::TYPE_GRAVPOINT) {
if (kid->GetSuperType() == SystemBody::SUPERTYPE_STAR)
parent->m_mass += kid->m_mass;
else
parent->m_mass += kid->m_mass / SUN_MASS_TO_EARTH_MASS;
}

kid->SetOrbitFromParameters();
kid->SetAtmFromParameters();

Expand Down

0 comments on commit a509330

Please sign in to comment.