Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 850c0ec8684e
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b8ebc64668de
Choose a head ref
  • 7 commits
  • 11 files changed
  • 1 contributor

Commits on Mar 8, 2017

  1. Copy the full SHA
    cdbfde9 View commit details
  2. DebugID

    eggrobin committed Mar 8, 2017
    Copy the full SHA
    b44e7e6 View commit details
  3. part

    eggrobin committed Mar 8, 2017
    Copy the full SHA
    20cd621 View commit details
  4. I accidentally a reference

    eggrobin committed Mar 8, 2017
    Copy the full SHA
    aa66bdf View commit details
  5. missing DebugID

    eggrobin committed Mar 8, 2017
    Copy the full SHA
    f6cd73d View commit details
  6. after pleroy's review

    eggrobin committed Mar 8, 2017
    Copy the full SHA
    46eaea0 View commit details
  7. Copy the full SHA
    b8ebc64 View commit details
4 changes: 4 additions & 0 deletions ksp_plugin/identification.hpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,10 @@
namespace principia {
namespace ksp_plugin {

// The GUID of a vessel, obtained by |v.id.ToString()| in C#. We use this as a
// key in an |std::map|.
using GUID = std::string;

// Corresponds to KSP's |Part.flightID|, *not* to |Part.uid|. C#'s |uint|
// corresponds to |uint32_t|.
using PartId = std::uint32_t;
16 changes: 13 additions & 3 deletions ksp_plugin/interface.cpp
Original file line number Diff line number Diff line change
@@ -536,19 +536,25 @@ void principia__InsertCelestialJacobiKeplerian(
// |plugin| must not be null. No transfer of ownership.
void principia__InsertOrKeepVessel(Plugin* const plugin,
char const* const vessel_guid,
char const* const vessel_name,
int const parent_index,
bool const loaded,
bool* inserted) {
journal::Method<journal::InsertOrKeepVessel> m(
{plugin, vessel_guid, parent_index, loaded}, {inserted});
{plugin, vessel_guid, vessel_name, parent_index, loaded}, {inserted});
CHECK_NOTNULL(plugin);
plugin->InsertOrKeepVessel(vessel_guid, parent_index, loaded, *inserted);
plugin->InsertOrKeepVessel(vessel_guid,
vessel_name,
parent_index,
loaded,
*inserted);
return m.Return();
}

void principia__InsertOrKeepLoadedPart(
Plugin* const plugin,
std::uint32_t const part_id,
char const* const name,
double const mass_in_tonnes,
char const* const vessel_guid,
int const main_body_index,
@@ -557,6 +563,7 @@ void principia__InsertOrKeepLoadedPart(
journal::Method<journal::InsertOrKeepLoadedPart> m(
{plugin,
part_id,
name,
mass_in_tonnes,
vessel_guid,
main_body_index,
@@ -565,6 +572,7 @@ void principia__InsertOrKeepLoadedPart(
CHECK_NOTNULL(plugin);
plugin->InsertOrKeepLoadedPart(
part_id,
name,
mass_in_tonnes * Tonne,
GetVessel(*plugin, vessel_guid),
main_body_index,
@@ -584,13 +592,15 @@ void principia__InsertOrKeepLoadedPart(
// |plugin| must not be null. No transfer of ownership.
void principia__InsertUnloadedPart(Plugin* const plugin,
PartId const part_id,
char const* const name,
char const* const vessel_guid,
QP const from_parent) {
journal::Method<journal::InsertUnloadedPart> m(
{plugin, part_id, vessel_guid, from_parent});
{plugin, part_id, name, vessel_guid, from_parent});
CHECK_NOTNULL(plugin);
plugin->InsertUnloadedPart(
part_id,
name,
vessel_guid,
RelativeDegreesOfFreedom<AliceSun>(
Displacement<AliceSun>(FromXYZ(from_parent.q) * Metre),
24 changes: 21 additions & 3 deletions ksp_plugin/part.cpp
Original file line number Diff line number Diff line change
@@ -3,28 +3,35 @@

#include "ksp_plugin/part.hpp"

#include "base/array.hpp"
#include "base/hexadecimal.hpp"
#include "base/not_null.hpp"

namespace principia {
namespace ksp_plugin {
namespace internal_part {

using base::Array;
using base::HexadecimalEncode;
using base::make_not_null_unique;
using base::UniqueBytes;

Part::Part(
PartId const part_id,
std::string const& name,
Mass const& mass,
DegreesOfFreedom<Barycentric> const& degrees_of_freedom,
std::function<void()> deletion_callback)
: part_id_(part_id),
name_(name),
mass_(mass),
degrees_of_freedom_(degrees_of_freedom),
tail_(make_not_null_unique<DiscreteTrajectory<Barycentric>>()),
subset_node_(make_not_null_unique<Subset<Part>::Node>()),
deletion_callback_(std::move(deletion_callback)) {}

Part::~Part() {
LOG(INFO) << "Destroying part " << part_id_;
LOG(INFO) << "Destroying part " << ShortDebugString();
CHECK(!is_piled_up());
if (deletion_callback_ != nullptr) {
deletion_callback_();
@@ -84,7 +91,7 @@ void Part::set_tail_is_authoritative(bool const tail_is_authoritative) {

void Part::set_containing_pile_up(IteratorOn<std::list<PileUp>> const pile_up) {
CHECK(!is_piled_up());
LOG(INFO) << "Adding part " << part_id_ << " to the pile up at "
LOG(INFO) << "Adding part " << ShortDebugString() << " to the pile up at "
<< &*pile_up.iterator();
containing_pile_up_ = pile_up;
}
@@ -103,7 +110,7 @@ void Part::clear_pile_up() {
if (is_piled_up()) {
IteratorOn<std::list<PileUp>> pile_up = *containing_pile_up_;
for (not_null<Part*> const part : pile_up.iterator()->parts()) {
LOG(INFO) << "Removing part " << part->part_id()
LOG(INFO) << "Removing part " << part->ShortDebugString()
<< " from its pile up at " << &*pile_up.iterator();
part->containing_pile_up_ = std::experimental::nullopt;
}
@@ -114,6 +121,7 @@ void Part::clear_pile_up() {

void Part::WriteToMessage(not_null<serialization::Part*> const message) const {
message->set_part_id(part_id_);
message->set_name(name_);
mass_.WriteToMessage(message->mutable_mass());
intrinsic_force_.WriteToMessage(message->mutable_intrinsic_force());
if (containing_pile_up_) {
@@ -129,6 +137,7 @@ not_null<std::unique_ptr<Part>> Part::ReadFromMessage(
std::function<void()> deletion_callback) {
not_null<std::unique_ptr<Part>> part =
make_not_null_unique<Part>(message.part_id(),
message.name(),
Mass::ReadFromMessage(message.mass()),
DegreesOfFreedom<Barycentric>::ReadFromMessage(
message.degrees_of_freedom()),
@@ -144,6 +153,15 @@ not_null<std::unique_ptr<Part>> Part::ReadFromMessage(
return part;
}

std::string Part::ShortDebugString() const {
UniqueBytes hex_id(sizeof(part_id_) * 2 + 1);
Array<std::uint8_t const> id_bytes(
reinterpret_cast<std::uint8_t const*>(&part_id_), sizeof(part_id_));
HexadecimalEncode(id_bytes, hex_id.get());
hex_id.data[sizeof(part_id_) * 2] = '\0';
return name_ + " (" + reinterpret_cast<char const*>(hex_id.data.get()) + ")";
}

std::ostream& operator<<(std::ostream& out, Part const& part) {
return out << "{"
<< part.part_id() << ", "
5 changes: 5 additions & 0 deletions ksp_plugin/part.hpp
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ using quantities::Mass;
class Part final {
public:
Part(PartId part_id,
std::string const& name,
Mass const& mass,
DegreesOfFreedom<Barycentric> const& degrees_of_freedom,
std::function<void()> deletion_callback);
@@ -100,8 +101,12 @@ class Part final {
serialization::Part const& message,
std::function<void()> deletion_callback);

// Returns "part name (part ID)".
std::string ShortDebugString() const;

private:
PartId const part_id_;
std::string const name_;
Mass mass_;
Vector<Force, Barycentric> intrinsic_force_;

21 changes: 15 additions & 6 deletions ksp_plugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -372,6 +372,7 @@ Time Plugin::CelestialRotationPeriod(Index const celestial_index) const {
}

void Plugin::InsertOrKeepVessel(GUID const& vessel_guid,
std::string const& vessel_name,
Index const parent_index,
bool const loaded,
bool& inserted) {
@@ -385,7 +386,9 @@ void Plugin::InsertOrKeepVessel(GUID const& vessel_guid,
GUIDToOwnedVessel::iterator it;
std::tie(it, inserted) =
vessels_.emplace(vessel_guid,
make_not_null_unique<Vessel>(parent,
make_not_null_unique<Vessel>(vessel_guid,
vessel_name,
parent,
ephemeris_.get(),
prediction_parameters_));
not_null<Vessel*> const vessel = it->second.get();
@@ -397,14 +400,14 @@ void Plugin::InsertOrKeepVessel(GUID const& vessel_guid,
new_unloaded_vessels_.insert(vessel);
}
LOG_IF(INFO, inserted) << "Inserted " << (loaded ? "loaded" : "unloaded")
<< " vessel with GUID " << vessel_guid << " at "
<< vessel;
VLOG(1) << "Parent of vessel with GUID " << vessel_guid << " is at index "
<< " vessel " << vessel->ShortDebugString();
VLOG(1) << "Parent of vessel " << vessel->ShortDebugString() << " is at index "
<< parent_index;
}

void Plugin::InsertUnloadedPart(
PartId part_id,
std::string const& name,
GUID const& vessel_guid,
RelativeDegreesOfFreedom<AliceSun> const& from_parent) {
not_null<Vessel*> const vessel = find_vessel_by_guid_or_die(vessel_guid).get();
@@ -414,6 +417,7 @@ void Plugin::InsertUnloadedPart(
ephemeris_->Prolong(current_time_);
AddPart(vessel,
part_id,
name,
1 * Kilogram,
vessel->parent()->current_degrees_of_freedom(current_time_) +
relative);
@@ -425,6 +429,7 @@ void Plugin::InsertUnloadedPart(

void Plugin::InsertOrKeepLoadedPart(
PartId const part_id,
std::string const& name,
Mass const& mass,
not_null<Vessel*> const vessel,
Index const main_body_index,
@@ -462,6 +467,7 @@ void Plugin::InsertOrKeepLoadedPart(

AddPart(vessel,
part_id,
name,
mass,
world_to_barycentric(part_degrees_of_freedom));
}
@@ -650,7 +656,7 @@ RelativeDegreesOfFreedom<AliceSun> Plugin::VesselFromParent(
vessel->parent()->current_degrees_of_freedom(current_time_);
RelativeDegreesOfFreedom<AliceSun> const result =
PlanetariumRotation()(barycentric_result);
VLOG(1) << "Vessel with GUID " << vessel_guid
VLOG(1) << "Vessel " << vessel->ShortDebugString()
<< " is at parent degrees of freedom + " << barycentric_result
<< " Barycentre (" << result << " AliceSun)";
return result;
@@ -697,7 +703,8 @@ Plugin::RenderedVesselTrajectory(
CHECK(!initializing_);
not_null<std::unique_ptr<Vessel>> const& vessel =
find_vessel_by_guid_or_die(vessel_guid);
VLOG(1) << "Rendering a trajectory for the vessel with GUID " << vessel_guid;
VLOG(1) << "Rendering a trajectory for the vessel "
<< vessel->ShortDebugString();
return RenderedTrajectoryFromIterators(vessel->psychohistory().Begin(),
vessel->psychohistory().End(),
sun_world_position);
@@ -1333,6 +1340,7 @@ std::uint64_t Plugin::FingerprintCelestialJacobiKeplerian(

void Plugin::AddPart(not_null<Vessel*> const vessel,
PartId const part_id,
std::string const& name,
Mass const mass,
DegreesOfFreedom<Barycentric> const& degrees_of_freedom) {
std::map<PartId, not_null<Vessel*>>::iterator it;
@@ -1343,6 +1351,7 @@ void Plugin::AddPart(not_null<Vessel*> const vessel,
map.erase(it);
};
auto part = make_not_null_unique<Part>(part_id,
name,
mass,
degrees_of_freedom,
std::move(deletion_callback));
8 changes: 4 additions & 4 deletions ksp_plugin/plugin.hpp
Original file line number Diff line number Diff line change
@@ -70,9 +70,6 @@ using quantities::si::Metre;
using quantities::si::Milli;
using quantities::si::Second;

// The GUID of a vessel, obtained by |v.id.ToString()| in C#. We use this as a
// key in an |std::map|.
using GUID = std::string;
// The index of a body in |FlightGlobals.Bodies|, obtained by
// |b.flightGlobalsIndex| in C#. We use this as a key in an |std::map|.
using Index = int;
@@ -154,6 +151,7 @@ class Plugin {
// For a KSP |Vessel| |v|, the arguments correspond to |v.id|,
// |v.orbit.referenceBody.flightGlobalsIndex|, |v.loaded|.
virtual void InsertOrKeepVessel(GUID const& vessel_guid,
std::string const& vessel_name,
Index parent_index,
bool loaded,
bool& inserted);
@@ -164,6 +162,7 @@ class Plugin {
// matter, since the |PileUp| will be deformed when it first loads anyway.
virtual void InsertUnloadedPart(
PartId part_id,
std::string const& name,
GUID const& vessel_guid,
RelativeDegreesOfFreedom<AliceSun> const& from_parent);

@@ -176,6 +175,7 @@ class Plugin {
// these three parameters are ignored.
virtual void InsertOrKeepLoadedPart(
PartId part_id,
std::string const& name,
Mass const& mass,
not_null<Vessel*> vessel,
Index main_body_index,
@@ -433,6 +433,7 @@ class Plugin {
// a deletion callback.
void AddPart(not_null<Vessel*> vessel,
PartId part_id,
std::string const& name,
Mass mass,
DegreesOfFreedom<Barycentric> const& degrees_of_freedom);

@@ -517,7 +518,6 @@ class Plugin {

} // namespace internal_plugin

using internal_plugin::GUID;
using internal_plugin::Index;
using internal_plugin::Plugin;

Loading