-
Notifications
You must be signed in to change notification settings - Fork 69
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
Part based pile ups in plugin #1220
Conversation
This reverts commit 8412121.
ksp_plugin/plugin.cpp
Outdated
CHECK(!initializing_); | ||
not_null<Celestial const*> parent = | ||
FindOrDie(celestials_, parent_index).get(); | ||
auto inserted = | ||
auto pair = |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ksp_plugin/plugin.cpp
Outdated
if (vessel == current_vessel) { | ||
vessel->KeepPart(part_id); | ||
} else { | ||
FindOrDie(part_id_to_vessel_, part_id) = vessel; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
ksp_plugin/plugin.cpp
Outdated
vessel->AddPart(current_vessel->ExtractPart(part_id)); | ||
} | ||
} else { | ||
auto const pair = part_id_to_vessel_.emplace(part_id, vessel); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::tie
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ksp_plugin/plugin.cpp
Outdated
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ksp_plugin/plugin.cpp
Outdated
it = vessels_.erase(it); | ||
} | ||
} | ||
// Free old parts, and bind vessels. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ksp_plugin/plugin.hpp
Outdated
// 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No const
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ksp_plugin/plugin.hpp
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass PartId
s by copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ksp_plugin/plugin.hpp
Outdated
GUIDToOwnedVessel vessels_; | ||
std::map<PartId, not_null<Vessel*>> part_id_to_vessel_; |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ksp_plugin/plugin.hpp
Outdated
@@ -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_; |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ksp_plugin/vessel.hpp
Outdated
@@ -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; |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, ForAllParts, ForSomePart.
ksp_plugin/plugin.hpp
Outdated
@@ -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. |
There was a problem hiding this comment.
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/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ksp_plugin/plugin.cpp
Outdated
Subset<Part>::Unite(Subset<Part>::Find(first_part), | ||
Subset<Part>::Find(part)); | ||
} | ||
vessel->ForSomePart([vessel](Part& first_part) { |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
No description provided.