Skip to content

Part based pile ups in plugin #1220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

eggrobin
Copy link
Member

@eggrobin eggrobin commented Mar 3, 2017

No description provided.

CHECK(!initializing_);
not_null<Celestial const*> parent =
FindOrDie(celestials_, parent_index).get();
auto inserted =
auto pair =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend to use std::tie for this kind of calls.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (vessel == current_vessel) {
vessel->KeepPart(part_id);
} else {
FindOrDie(part_id_to_vessel_, part_id) = vessel;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not it->second on the LHS to avoid a second lookup?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (with a reference, so we can have names)

vessel->AddPart(current_vessel->ExtractPart(part_id));
}
} else {
auto const pair = part_id_to_vessel_.emplace(part_id, vessel);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::tie.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

not_null<Vessel*> const vessel,
DegreesOfFreedom<Barycentric> const& degrees_of_freedom) {
auto it = part_id_to_vessel_.find(part_id);
bool const found = it != part_id_to_vessel_.end();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this part_found to clarify what is found.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

it = vessels_.erase(it);
}
}
// Free old parts, and bind vessels.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comma here, it's not an enumeration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// Calls |SetPartApparentDegreesOfFreedom| on the pile-up containing the
// relevant part. This part must be in a loaded vessel.
virtual void SetPartApparentDegreesOfFreedom(
PartId const part_id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No const.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -290,7 +308,7 @@ class Plugin {

// Notifies |this| that the given vessels are touching, and should gravitate
// as part of a single rigid body.
virtual void ReportCollision(GUID const& vessel1, GUID const& vessel2) const;
virtual void ReportCollision(PartId const& part1, PartId const& part2) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass PartIds by copy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

GUIDToOwnedVessel vessels_;
std::map<PartId, not_null<Vessel*>> part_id_to_vessel_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document this map: "For each part, the vessel that this part belongs to. The part is guaranteed to be part of the parts() map of the vessel, and owned by it."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -460,7 +476,7 @@ class Plugin {
// Do not |erase| from this list, use |Vessel::clear_pile_up| instead.
std::list<PileUp> pile_ups_;

std::list<std::list<PileUp>::iterator> pile_ups_in_bubble_;
std::set<not_null<Vessel*>> loaded_vessels_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: "The vessels that are currently loaded, i.e. in the physics bubble."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -83,9 +83,15 @@ class Vessel {
// Returns the part with the given ID. Such a part must have been added using
// |AddPart|.
virtual not_null<Part*> part(PartId id) const;
virtual std::map<PartId, not_null<std::unique_ptr<Part>>> const& parts()
const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bit of an abstraction leak here as we expose the data structure internal to the vessel. Maybe it would be better to have GetSomePart (returning the first one, but that's not part of the contract) and DoForAllParts (taking a lambda).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, ForAllParts, ForSomePart.

@@ -419,6 +425,8 @@ class Plugin {
bool is_loaded(not_null<Vessel*> vessel) const;

GUIDToOwnedVessel vessels_;
// For each part, the vessel that this part belongs to. The part is guaranteed
// to be part of the parts() map of the vessel, and owned by it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/to be part of/to be in/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Subset<Part>::Unite(Subset<Part>::Find(first_part),
Subset<Part>::Find(part));
}
vessel->ForSomePart([vessel](Part& first_part) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it work to make this const&? (Same question in other places.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

@pleroy pleroy added the LGTM label Mar 4, 2017
@eggrobin eggrobin merged commit 5253a03 into mockingbirdnest:Cardano Mar 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants