Skip to content
Permalink
Browse files

After pleroy's review

  • Loading branch information...
eggrobin committed Sep 21, 2014
1 parent 1aa9a51 commit 1b72c600ecd729b92439f509e53263f78900ba18
Showing with 303 additions and 225 deletions.
  1. +1 βˆ’1 geometry/permutation_body.hpp
  2. +31 βˆ’25 ksp_plugin/interface.cpp
  3. +47 βˆ’19 ksp_plugin/interface.hpp
  4. +93 βˆ’79 ksp_plugin/plugin.cpp
  5. +100 βˆ’68 ksp_plugin/plugin.hpp
  6. +31 βˆ’33 ksp_plugin_adapter/ksp_plugin_adapter.cs
@@ -152,7 +152,7 @@ Permutation<FromFrame, ToFrame> operator*(
{{Right::YXZ, Left::ZYX}, Result::ZXY},
{{Right::YXZ, Left::YXZ}, Result::XYZ}};
return Result(multiplication.at({right.coordinate_permutation_,
left.coordinate_permutation_}));
left.coordinate_permutation_}));
}

} // namespace geometry
@@ -24,102 +24,108 @@ void InitGoogleLogging() {
LOG(INFO) << "Initialized Google logging for Principia.";
}

void LOGINFO(char const* message) {
void LogInfo(char const* message) {
LOG(INFO) << message;
}

void LOGWARNING(char const* message) {
void LogWarning(char const* message) {
LOG(WARNING) << message;
}

void LOGERROR(char const* message) {
void LogError(char const* message) {
LOG(ERROR) << message;
}

void LOGFATAL(char const* message) {
void LogFatal(char const* message) {
LOG(FATAL) << message;
}

Plugin* CreatePlugin(double const initial_time, int const sun_index,
Plugin* NewPlugin(double const initial_time, int const sun_index,
double const sun_gravitational_parameter,
double const planetarium_rotation_in_degrees) {
LOG(INFO) << "Creating Principia...";
LOG(INFO) << "Constructing Principia plugin...";
return new Plugin(
Instant(initial_time * Second),
sun_index,
sun_gravitational_parameter * SIUnit<GravitationalParameter>(),
planetarium_rotation_in_degrees * Degree);
LOG(INFO) << "Plugin created.";
LOG(INFO) << "Plugin constructed.";
}

void DestroyPlugin(Plugin* plugin) {
delete plugin;
plugin = nullptr;
LOG(INFO) << "Destroyed Principia.";
void DeletePlugin(Plugin** const plugin) {
LOG(INFO) << "Destroying Principia plugin...";
delete *plugin;
*plugin = nullptr;
LOG(INFO) << "Plugin destroyed.";
}

// NOTE(egg): the |* (Metre / Second)| might be slower than |* SIUnit<Speed>()|,
// but it is more readable. This will be resolved once we have |constexpr|.

void InsertCelestial(Plugin* plugin, int const index,
double const gravitational_parameter,
int const parent,
XYZ const from_parent_position,
XYZ const from_parent_velocity) {
plugin->InsertCelestial(
CHECK_NOTNULL(plugin)->InsertCelestial(
index,
gravitational_parameter * SIUnit<GravitationalParameter>(),
parent,
Displacement<AliceSun>({from_parent_position.x * Metre,
from_parent_position.y * Metre,
from_parent_position.z * Metre}),
Velocity<AliceSun>({from_parent_velocity.x * Metre / Second,
from_parent_velocity.y * Metre / Second,
from_parent_velocity.z * Metre / Second}));
Velocity<AliceSun>({from_parent_velocity.x * (Metre / Second),
from_parent_velocity.y * (Metre / Second),
from_parent_velocity.z * (Metre / Second)}));
}

void UpdateCelestialHierarchy(Plugin* plugin, int const index,
int const parent) {
plugin->UpdateCelestialHierarchy(index, parent);
CHECK_NOTNULL(plugin)->UpdateCelestialHierarchy(index, parent);
}

void InsertOrKeepVessel(Plugin* plugin, char const* guid, int const parent) {
plugin->InsertOrKeepVessel(guid, parent);
CHECK_NOTNULL(plugin)->InsertOrKeepVessel(guid, parent);
}

void SetVesselStateOffset(Plugin* plugin, char const* guid,
XYZ const from_parent_position,
XYZ const from_parent_velocity) {
plugin->SetVesselStateOffset(
CHECK_NOTNULL(plugin)->SetVesselStateOffset(
guid,
Displacement<AliceSun>({from_parent_position.x * Metre,
from_parent_position.y * Metre,
from_parent_position.z * Metre}),
Velocity<AliceSun>({from_parent_velocity.x * Metre / Second,
from_parent_velocity.y * Metre / Second,
from_parent_velocity.z * Metre / Second}));
Velocity<AliceSun>({from_parent_velocity.x * (Metre / Second),
from_parent_velocity.y * (Metre / Second),
from_parent_velocity.z * (Metre / Second)}));
}

XYZ VesselDisplacementFromParent(Plugin* plugin, char const* guid) {
R3Element<Length> const result =
plugin->VesselDisplacementFromParent(guid).coordinates();
CHECK_NOTNULL(plugin)->VesselDisplacementFromParent(guid).coordinates();
return {result.x / Metre, result.y / Metre, result.z / Metre};
}

XYZ VesselParentRelativeVelocity(Plugin* plugin, char const* guid) {
R3Element<Speed> const result =
plugin->VesselParentRelativeVelocity(guid).coordinates();
CHECK_NOTNULL(plugin)->VesselParentRelativeVelocity(guid).coordinates();
return {result.x / (Metre / Second),
result.y / (Metre / Second),
result.z / (Metre / Second)};
}

XYZ CelestialDisplacementFromParent(Plugin* plugin, int const index) {
R3Element<Length> const result =
plugin->CelestialDisplacementFromParent(index).coordinates();
CHECK_NOTNULL(plugin)->
CelestialDisplacementFromParent(index).coordinates();
return {result.x / Metre, result.y / Metre, result.z / Metre};;
}

XYZ CelestialParentRelativeVelocity(Plugin* plugin, int const index) {
R3Element<Speed> const result =
plugin->CelestialParentRelativeVelocity(index).coordinates();
CHECK_NOTNULL(plugin)->
CelestialParentRelativeVelocity(index).coordinates();
return {result.x / (Metre / Second),
result.y / (Metre / Second),
result.z / (Metre / Second)};
@@ -6,17 +6,24 @@

// DLL-exported functions for interfacing with Platform Invocation Services.

#if defined(DLLEXPORT)
#error "DLLEXPORT already defined"
#else
#if defined(_WIN32)
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __attribute__((visibility("default")))
#endif
#endif

namespace principia {
namespace ksp_plugin {

extern "C"
struct XYZ { double x, y, z; };
struct XYZ {
double x, y, z;
};

static_assert(std::is_standard_layout<XYZ>::value,
"XYZ is used for interfacing");

@@ -33,68 +40,89 @@ extern "C" DLLEXPORT
void InitGoogleLogging();

// Exports |LOG(SEVERITY) << message| for fast logging from the C# adapter.
// This will always evaluate its argument even if the corresponding log severity
// is disabled, so it is less efficient than LOG(INFO). It will not report the
// line and file of the caller.
extern "C" DLLEXPORT
void LOGINFO(char const* message);
void LogInfo(char const* message);
extern "C" DLLEXPORT
void LOGWARNING(char const* message);
void LogWarning(char const* message);
extern "C" DLLEXPORT
void LOGERROR(char const* message);
void LogError(char const* message);
extern "C" DLLEXPORT
void LOGFATAL(char const* message);
void LogFatal(char const* message);

// Returns a pointer to a plugin constructed with the arguments given.
// The caller takes ownership of the result.
extern "C" DLLEXPORT
Plugin* CreatePlugin(double const initial_time, int const sun_index,
double const sun_gravitational_parameter,
double const planetarium_rotation_in_degrees);
Plugin* NewPlugin(double const initial_time,
int const sun_index,
double const sun_gravitational_parameter,
double const planetarium_rotation_in_degrees);

// Deletes |plugin|.
// Deletes and nulls |*plugin|.
// No transfer of ownership of |*plugin|, takes ownership of |**plugin|.
extern "C" DLLEXPORT
void DestroyPlugin(Plugin* plugin);
void DeletePlugin(Plugin** const plugin);

// Calls |plugin->InsertCelestial| with the arguments given.
// |plugin| should not be null. No transfer of ownership.
extern "C" DLLEXPORT
void InsertCelestial(Plugin* plugin, int const index,
void InsertCelestial(Plugin* const plugin,
int const index,
double const gravitational_parameter,
int const parent,
XYZ const from_parent_position,
XYZ const from_parent_velocity);

// Calls |plugin->InsertCelestial| with the arguments given.
// Calls |plugin->UpdateCelestialHierarchy| with the arguments given.
// |plugin| should not be null. No transfer of ownership.
extern "C" DLLEXPORT
void UpdateCelestialHierarchy(Plugin* plugin, int const index,
void UpdateCelestialHierarchy(Plugin* const plugin,
int const index,
int const parent);

// Calls |plugin->InsertOrKeepVessel| with the arguments given.
// |plugin| should not be null. No transfer of ownership.
extern "C" DLLEXPORT
void InsertOrKeepVessel(Plugin* plugin, char const* guid, int const parent);
void InsertOrKeepVessel(Plugin* const plugin, char const* guid,
int const parent);

// Calls |plugin->SetVesselStateOffset| with the arguments given.
// |plugin| should not be null. No transfer of ownership.
extern "C" DLLEXPORT
void SetVesselStateOffset(Plugin* plugin, char const* guid,
void SetVesselStateOffset(Plugin* const plugin,
char const* guid,
XYZ const from_parent_position,
XYZ const from_parent_velocity);

// Calls |plugin->VesselDisplacementFromParent| with the arguments given.
// |plugin| should not be null. No transfer of ownership.
extern "C" DLLEXPORT
XYZ VesselDisplacementFromParent(Plugin* plugin,
XYZ VesselDisplacementFromParent(Plugin* const plugin,
char const* guid);

// Calls |plugin->VesselParentRelativeVelocity| with the arguments given.
// |plugin| should not be null. No transfer of ownership.
extern "C" DLLEXPORT
XYZ VesselParentRelativeVelocity(Plugin* plugin,
XYZ VesselParentRelativeVelocity(Plugin* const plugin,
char const* guid);

// Calls |plugin->CelestialDisplacementFromParent| with the arguments given.
// |plugin| should not be null. No transfer of ownership.
extern "C" DLLEXPORT
XYZ CelestialDisplacementFromParent(Plugin* plugin, int const index);
XYZ CelestialDisplacementFromParent(Plugin* const plugin, int const index);

// Calls |plugin->CelestialParentRelativeVelocity| with the arguments given.
// |plugin| should not be null. No transfer of ownership.
extern "C" DLLEXPORT
XYZ CelestialParentRelativeVelocity(Plugin* plugin, int const index);
XYZ CelestialParentRelativeVelocity(Plugin* const plugin, int const index);

// Says hello, convenient for checking that calls to the dll work.
extern "C" DLLEXPORT
char const* SayHello();

} // namespace ksp_plugin
} // namespace principia

#undef DLLEXPORT

0 comments on commit 1b72c60

Please sign in to comment.
You can’t perform that action at this time.