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: f7e491f4391a
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 54b64f79cbd2
Choose a head ref
  • 12 commits
  • 13 files changed
  • 1 contributor

Commits on May 21, 2020

  1. Copy the full SHA
    e1f3731 View commit details
  2. Journal and C# changes.

    pleroy committed May 21, 2020
    Copy the full SHA
    847787a View commit details
  3. Const the returned pointers.

    pleroy committed May 21, 2020
    Copy the full SHA
    7957b14 View commit details
  4. Construction of statuses on the C++ side. Also, use predefined type n…

    …ames in the generator.
    pleroy committed May 21, 2020
    Copy the full SHA
    2ac2ded View commit details
  5. Copy the full SHA
    5b6bd90 View commit details
  6. Copy the full SHA
    7098fb9 View commit details
  7. Copy the full SHA
    a7da77c View commit details
  8. Remove the generated files.

    pleroy committed May 21, 2020
    Copy the full SHA
    2392649 View commit details
  9. Fix the tests.

    pleroy committed May 21, 2020
    Copy the full SHA
    ec4f6ff View commit details
  10. Lint.

    pleroy committed May 21, 2020
    Copy the full SHA
    e60cc36 View commit details

Commits on May 22, 2020

  1. After egg's review.

    pleroy committed May 22, 2020
    Copy the full SHA
    f7e0795 View commit details

Commits on May 23, 2020

  1. Merge pull request #2588 from pleroy/2585a

    Add support for transmitting the status's message to the C# code
    pleroy authored May 23, 2020
    Copy the full SHA
    54b64f7 View commit details
14 changes: 7 additions & 7 deletions journal/profiles.cpp
Original file line number Diff line number Diff line change
@@ -18,9 +18,9 @@ namespace journal {
namespace {

template<typename T>
void Insert(Player::PointerMap& pointer_map,
std::uint64_t const address,
T* const pointer) {
void Insert(std::uint64_t const address,
T* const pointer,
Player::PointerMap& pointer_map) {
void* const inserted_pointer = static_cast<void*>(
const_cast<typename std::remove_cv<T>::type*>(pointer));
auto const [it, inserted] = pointer_map.emplace(address, inserted_pointer);
@@ -29,8 +29,8 @@ void Insert(Player::PointerMap& pointer_map,
}
}

void Delete(Player::PointerMap& pointer_map,
std::uint64_t const address) {
void Delete(std::uint64_t const address,
Player::PointerMap& pointer_map) {
if (reinterpret_cast<void*>(address) != nullptr) {
auto const it = pointer_map.find(address);
CHECK(it != pointer_map.end()) << address;
@@ -40,8 +40,8 @@ void Delete(Player::PointerMap& pointer_map,

template<typename T,
typename = typename std::enable_if<std::is_pointer<T>::value>::type>
T DeserializePointer(Player::PointerMap const& pointer_map,
std::uint64_t const address) {
T DeserializePointer(std::uint64_t const address,
Player::PointerMap const& pointer_map) {
if (reinterpret_cast<T>(address) == nullptr) {
return nullptr;
} else {
5 changes: 4 additions & 1 deletion ksp_plugin/interface.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#pragma once

#include <string>
#include <typeindex>
#include <type_traits>
#include <utility>
@@ -155,7 +156,9 @@ KeplerianElements ToKeplerianElements(
QP ToQP(DegreesOfFreedom<World> const& dof);
QP ToQP(RelativeDegreesOfFreedom<AliceSun> const& relative_dof);

Status ToStatus(base::Status const& status);
// Ownership of the status and its message is transferred to the caller.
Status* ToNewStatus(base::Status const& status);
Status* ToNewStatus(base::Error error, std::string const& message);

WXYZ ToWXYZ(geometry::Quaternion const& quaternion);

25 changes: 21 additions & 4 deletions ksp_plugin/interface_body.hpp
Original file line number Diff line number Diff line change
@@ -5,8 +5,10 @@

#include <cmath>
#include <limits>
#include <string>
#include <utility>

#include "base/array.hpp"
#include "geometry/named_quantities.hpp"
#include "geometry/orthogonal_map.hpp"
#include "geometry/rotation.hpp"
@@ -17,6 +19,7 @@
namespace principia {
namespace interface {

using base::UniqueArray;
using geometry::OrthogonalMap;
using geometry::RigidTransformation;
using geometry::Rotation;
@@ -449,11 +452,25 @@ inline QP ToQP(RelativeDegreesOfFreedom<AliceSun> const& relative_dof) {
return QPConverter<RelativeDegreesOfFreedom<AliceSun>>::ToQP(relative_dof);
}

inline Status ToStatus(base::Status const& status) {
if (!status.ok()) {
LOG(ERROR) << status.message();
inline Status* ToNewStatus(base::Status const& status) {
if (status.ok()) {
return new Status{static_cast<int>(status.error()),
/*message=*/nullptr};
} else {
std::string const& message = status.message();
LOG(ERROR) << message;
UniqueArray<char> allocated_message(message.size() + 1);
std::memcpy(allocated_message.data.get(),
message.c_str(),
message.size() + 1);
return new Status{static_cast<int>(status.error()),
allocated_message.data.release()};
}
return {static_cast<int>(status.error())};
}

inline Status* ToNewStatus(base::Error const error,
std::string const& message) {
return ToNewStatus(base::Status(error, message));
}

inline WXYZ ToWXYZ(geometry::Quaternion const& quaternion) {
91 changes: 43 additions & 48 deletions ksp_plugin/interface_external.cpp
Original file line number Diff line number Diff line change
@@ -35,19 +35,14 @@ using physics::RigidTransformation;

namespace {

// A wrapper for |MakeStatus(base::Status(error, message))|, since we often
// construct the status in the interface itself.
Status MakeStatus(Error const error, std::string const& message) {
return ToStatus(base::Status(error, message));
}

Status OK() {
return ToStatus(base::Status::OK);
Status* OK() {
static Status* const ok = ToNewStatus(base::Status::OK);
return ok;
}

} // namespace

Status __cdecl principia__ExternalCelestialGetPosition(
Status* __cdecl principia__ExternalCelestialGetPosition(
Plugin const* const plugin,
int const body_index,
double const time,
@@ -59,10 +54,10 @@ Status __cdecl principia__ExternalCelestialGetPosition(
{position}};
if (plugin == nullptr) {
return m.Return(
MakeStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
ToNewStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
}
if (!plugin->HasCelestial(body_index)) {
return m.Return(MakeStatus(
return m.Return(ToNewStatus(
Error::NOT_FOUND,
absl::StrCat("No celestial with index ", body_index)));
}
@@ -71,12 +66,12 @@ Status __cdecl principia__ExternalCelestialGetPosition(
Instant const t = FromGameTime(*plugin, time);
if (t < trajectory.t_min() || t > trajectory.t_max()) {
return m.Return(
MakeStatus(Error::OUT_OF_RANGE,
(std::stringstream{}
<< "|time| " << t << " does not lie within the domain ["
<< trajectory.t_min() << ", " << trajectory.t_max()
<< "] of the trajectory of " << celestial.body()->name())
.str()));
ToNewStatus(Error::OUT_OF_RANGE,
(std::stringstream{}
<< "|time| " << t << " does not lie within the domain ["
<< trajectory.t_min() << ", " << trajectory.t_max()
<< "] of the trajectory of " << celestial.body()->name())
.str()));
}
auto const from_solar_system_barycentre =
plugin->renderer().BarycentricToWorldSun(plugin->PlanetariumRotation())(
@@ -85,7 +80,7 @@ Status __cdecl principia__ExternalCelestialGetPosition(
return m.Return(OK());
}

Status __cdecl principia__ExternalCelestialGetSurfacePosition(
Status* __cdecl principia__ExternalCelestialGetSurfacePosition(
Plugin const* const plugin,
int const body_index,
double const planetocentric_latitude_in_degrees,
@@ -103,10 +98,10 @@ Status __cdecl principia__ExternalCelestialGetSurfacePosition(
{position}};
if (plugin == nullptr) {
return m.Return(
MakeStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
ToNewStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
}
if (!plugin->HasCelestial(body_index)) {
return m.Return(MakeStatus(
return m.Return(ToNewStatus(
Error::NOT_FOUND,
absl::StrCat("No celestial with index ", body_index)));
}
@@ -115,12 +110,12 @@ Status __cdecl principia__ExternalCelestialGetSurfacePosition(
Instant const t = FromGameTime(*plugin, time);
if (t < trajectory.t_min() || t > trajectory.t_max()) {
return m.Return(
MakeStatus(Error::OUT_OF_RANGE,
(std::stringstream{}
<< "|time| " << t << " does not lie within the domain ["
<< trajectory.t_min() << ", " << trajectory.t_max()
<< "] of the trajectory of " << celestial.body()->name())
.str()));
ToNewStatus(Error::OUT_OF_RANGE,
(std::stringstream{}
<< "|time| " << t << " does not lie within the domain ["
<< trajectory.t_min() << ", " << trajectory.t_max()
<< "] of the trajectory of " << celestial.body()->name())
.str()));
}
using Surface = Frame<enum class SurfaceTag>;
OrthogonalMap<Surface, WorldSun> const to_world_axes =
@@ -136,7 +131,7 @@ Status __cdecl principia__ExternalCelestialGetSurfacePosition(
return m.Return(OK());
}

Status __cdecl principia__ExternalFlowFreefall(
Status* __cdecl principia__ExternalFlowFreefall(
Plugin const* const plugin,
int const central_body_index,
QP const world_body_centred_initial_degrees_of_freedom,
@@ -152,13 +147,13 @@ Status __cdecl principia__ExternalFlowFreefall(
{world_body_centred_final_degrees_of_freedom}};
if (plugin == nullptr) {
return m.Return(
MakeStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
ToNewStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
}
return m.Return(MakeStatus(Error::UNIMPLEMENTED,
return m.Return(ToNewStatus(Error::UNIMPLEMENTED,
"|ExternalFlowFreefall| is not yet implemented"));
}

Status __cdecl principia__ExternalGeopotentialGetCoefficient(
Status* __cdecl principia__ExternalGeopotentialGetCoefficient(
Plugin const* const plugin,
int const body_index,
int const degree,
@@ -172,15 +167,15 @@ Status __cdecl principia__ExternalGeopotentialGetCoefficient(
{coefficient}};
if (plugin == nullptr) {
return m.Return(
MakeStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
ToNewStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
}
if (!plugin->HasCelestial(body_index)) {
return m.Return(MakeStatus(
return m.Return(ToNewStatus(
Error::NOT_FOUND,
absl::StrCat("No celestial with index ", body_index)));
}
if (order < 0 || order > degree) {
return m.Return(MakeStatus(
return m.Return(ToNewStatus(
Error::INVALID_ARGUMENT,
absl::StrCat(u8"Expected 0 ≤ order ≤ degree; got degree = ",
degree, ", order = ", order)));
@@ -204,7 +199,7 @@ Status __cdecl principia__ExternalGeopotentialGetCoefficient(
return m.Return(OK());
}

Status __cdecl principia__ExternalGeopotentialGetReferenceRadius(
Status* __cdecl principia__ExternalGeopotentialGetReferenceRadius(
Plugin const* const plugin,
int const body_index,
double* const reference_radius) {
@@ -214,10 +209,10 @@ Status __cdecl principia__ExternalGeopotentialGetReferenceRadius(
{reference_radius}};
if (plugin == nullptr) {
return m.Return(
MakeStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
ToNewStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
}
if (!plugin->HasCelestial(body_index)) {
return m.Return(MakeStatus(
return m.Return(ToNewStatus(
Error::NOT_FOUND,
absl::StrCat("No celestial with index ", body_index)));
}
@@ -231,7 +226,7 @@ Status __cdecl principia__ExternalGeopotentialGetReferenceRadius(
return m.Return(OK());
}

Status __cdecl principia__ExternalGetNearestPlannedCoastDegreesOfFreedom(
Status* __cdecl principia__ExternalGetNearestPlannedCoastDegreesOfFreedom(
Plugin const* const plugin,
int const central_body_index,
char const* const vessel_guid,
@@ -247,32 +242,32 @@ Status __cdecl principia__ExternalGetNearestPlannedCoastDegreesOfFreedom(
{world_body_centred_nearest_degrees_of_freedom}};
if (plugin == nullptr) {
return m.Return(
MakeStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
ToNewStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
}
if (manoeuvre_index < 0) {
return m.Return(MakeStatus(Error::INVALID_ARGUMENT,
return m.Return(ToNewStatus(Error::INVALID_ARGUMENT,
"Invalid negative |manoeuvre_index|" +
std::to_string(manoeuvre_index)));
}
if (!plugin->HasCelestial(central_body_index)) {
return m.Return(MakeStatus(
return m.Return(ToNewStatus(
Error::NOT_FOUND,
"No celestial with index " + std::to_string(central_body_index)));
}
if (!plugin->HasVessel(vessel_guid)) {
return m.Return(MakeStatus(
return m.Return(ToNewStatus(
Error::NOT_FOUND,
"No vessel with GUID " + std::string(vessel_guid)));
}
Vessel const& vessel = *plugin->GetVessel(vessel_guid);
if (!vessel.has_flight_plan()) {
return m.Return(MakeStatus(
return m.Return(ToNewStatus(
Error::FAILED_PRECONDITION,
"Vessel " + vessel.ShortDebugString() + " has no flight plan"));
}
FlightPlan const& flight_plan = vessel.flight_plan();
if (manoeuvre_index >= flight_plan.number_of_manœuvres()) {
return m.Return(MakeStatus(
return m.Return(ToNewStatus(
Error::OUT_OF_RANGE,
"|manoeuvre_index| " + std::to_string(manoeuvre_index) +
" out of range, vessel " + vessel.ShortDebugString() + " has " +
@@ -282,7 +277,7 @@ Status __cdecl principia__ExternalGetNearestPlannedCoastDegreesOfFreedom(
// The index of the coast segment following the desired manœuvre.
int const segment_index = manoeuvre_index * 2 + 2;
if (segment_index >= flight_plan.number_of_segments()) {
return m.Return(MakeStatus(Error::FAILED_PRECONDITION,
return m.Return(ToNewStatus(Error::FAILED_PRECONDITION,
u8"A singularity occurs within manœuvre " +
std::to_string(manoeuvre_index) + " of " +
vessel.ShortDebugString()));
@@ -353,7 +348,7 @@ Status __cdecl principia__ExternalGetNearestPlannedCoastDegreesOfFreedom(
return m.Return(OK());
}

Status __cdecl principia__ExternalVesselGetPosition(
Status* __cdecl principia__ExternalVesselGetPosition(
Plugin const* const plugin,
char const* const vessel_guid,
double const time,
@@ -365,18 +360,18 @@ Status __cdecl principia__ExternalVesselGetPosition(
{position}};
if (plugin == nullptr) {
return m.Return(
MakeStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
ToNewStatus(Error::INVALID_ARGUMENT, "|plugin| must not be null"));
}
if (!plugin->HasVessel(vessel_guid)) {
return m.Return(MakeStatus(
return m.Return(ToNewStatus(
Error::NOT_FOUND,
absl::StrCat("No vessel with GUID ", vessel_guid)));
}
auto const& vessel = *plugin->GetVessel(vessel_guid);
auto const& trajectory = vessel.psychohistory();
Instant const t = FromGameTime(*plugin, time);
if (t < trajectory.t_min() || t > trajectory.t_max()) {
return m.Return(MakeStatus(
return m.Return(ToNewStatus(
Error::OUT_OF_RANGE,
(std::stringstream{}
<< "|time| " << t << " does not lie within the domain ["
Loading