Skip to content
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

The return of the plugin #151

Merged
merged 54 commits into from Sep 21, 2014
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ff2eb93
bikeshedding
eggrobin Sep 3, 2014
b348f44
Add some files.
eggrobin Sep 4, 2014
9828fc7
Merge branch 'master' into the-return-of-the-plugin
eggrobin Sep 4, 2014
2ad75f3
Manage the vessels and celestials.
eggrobin Sep 5, 2014
39c9067
Implement.
eggrobin Sep 5, 2014
01d5d3a
things
eggrobin Sep 6, 2014
55c0d21
moar headers
eggrobin Sep 6, 2014
02ea212
valse hésitation
eggrobin Sep 6, 2014
94a5616
This API is starting to make sense...
eggrobin Sep 6, 2014
ad0d6d2
Give the sun to the constructor, so we don't need to pass pointers
eggrobin Sep 6, 2014
2cf8c34
?
eggrobin Sep 7, 2014
e2b4f4f
Merge branch 'master' into the-return-of-the-plugin
eggrobin Sep 9, 2014
62bd7a0
things
eggrobin Sep 9, 2014
b3d1eb8
things
eggrobin Sep 9, 2014
623aec7
Merge remote-tracking branch 'la-vache/master' into the-return-of-the…
eggrobin Sep 9, 2014
9d11b86
waiting for a cl to be merged
eggrobin Sep 10, 2014
4302a4d
Merge remote-tracking branch 'la-vache/pr/148' into the-return-of-the…
eggrobin Sep 10, 2014
9ac0f93
resume working
eggrobin Sep 10, 2014
4cd1112
yet another method
eggrobin Sep 10, 2014
b1d0ced
Merge remote-tracking branch 'la-vache/master' into the-return-of-the…
eggrobin Sep 10, 2014
716c98a
It compiles *something*.
eggrobin Sep 11, 2014
8c376c3
There was a bug in Permutation.
eggrobin Sep 11, 2014
1c4c62e
state-setting implemented
eggrobin Sep 11, 2014
7e9d6ce
make it compile
eggrobin Sep 11, 2014
499bbbc
misc lint
eggrobin Sep 11, 2014
a4303cd
Integrate.
eggrobin Sep 11, 2014
8da9bbf
4 feedback methods.
eggrobin Sep 11, 2014
1aedcfa
preprocessor nonsense
eggrobin Sep 11, 2014
4a90f94
Typo.
eggrobin Sep 13, 2014
f0220e1
Typo!
eggrobin Sep 14, 2014
71779e8
Typo...
eggrobin Sep 15, 2014
c246dc0
Interface for a planet-pinning mod.
eggrobin Sep 16, 2014
b3434f3
It's been too long since the last commit...
eggrobin Sep 16, 2014
378e3ce
Rebooting!
eggrobin Sep 17, 2014
b503dd3
DFS
eggrobin Sep 18, 2014
b62d365
Document and assert.
eggrobin Sep 18, 2014
91e78fb
It compiles...
eggrobin Sep 19, 2014
3c829c9
Hooray segfaults!
eggrobin Sep 19, 2014
005ab0d
Initialise that pointer....
eggrobin Sep 19, 2014
d758ad7
ugly
eggrobin Sep 19, 2014
d51f345
blah
eggrobin Sep 19, 2014
540d124
more logging stuff
eggrobin Sep 19, 2014
d2e222d
reword comment
eggrobin Sep 19, 2014
2bc4a08
Follow the docs
eggrobin Sep 19, 2014
6b51ad4
LOG(INFO) << all_the_things;
eggrobin Sep 20, 2014
b63d3b3
Enough logging to find a bug
eggrobin Sep 20, 2014
aad7372
VLOG(1) << things_that_get_called_all_the_time
eggrobin Sep 20, 2014
70bb429
No Unity logging. Unity logging is slow.
eggrobin Sep 20, 2014
b6a81a5
lint
eggrobin Sep 20, 2014
83b67f1
CL time, merging master
eggrobin Sep 20, 2014
3e9f23a
more lint.
eggrobin Sep 20, 2014
1aa9a51
obsolete log
eggrobin Sep 20, 2014
3ce8341
After pleroy's review
eggrobin Sep 21, 2014
39fc5f8
After pleroy's second review
eggrobin Sep 21, 2014
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

After pleroy's review

  • Loading branch information...
eggrobin committed Sep 21, 2014
commit 3ce83411bdbc958a9c420c15c50a42d33703bf2f
@@ -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,121 @@ 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,
double const sun_gravitational_parameter,
double const planetarium_rotation_in_degrees) {
LOG(INFO) << "Creating Principia...";
Plugin* NewPlugin(double const initial_time,
int const sun_index,
double const sun_gravitational_parameter,
double const planetarium_rotation_in_degrees) {
LOG(INFO) << "Constructing Principia plugin...";
return new Plugin(

This comment has been minimized.

Copy link
@pleroy

pleroy Sep 21, 2014

Member

Methinks that the arguments might fit immediately after the (.

This comment has been minimized.

Copy link
@eggrobin

eggrobin Sep 21, 2014

Author Member

sun_gravitational_parameter * SIUnit<GravitationalParameter>(), definitely does not.

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** const plugin) {
LOG(INFO) << "Destroying Principia plugin...";
delete *plugin;
*plugin = nullptr;
LOG(INFO) << "Plugin destroyed.";
}

void InsertCelestial(Plugin* plugin, int const index,
// 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* const plugin,
int const celestial_index,
double const gravitational_parameter,
int const parent,
int const parent_index,
XYZ const from_parent_position,
XYZ const from_parent_velocity) {
plugin->InsertCelestial(
index,
CHECK_NOTNULL(plugin)->InsertCelestial(
celestial_index,
gravitational_parameter * SIUnit<GravitationalParameter>(),
parent,
parent_index,
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);
void UpdateCelestialHierarchy(Plugin const* const plugin,
int const celestial_index,
int const parent_index) {
CHECK_NOTNULL(plugin)->UpdateCelestialHierarchy(celestial_index,
parent_index);
}

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

void SetVesselStateOffset(Plugin* plugin, char const* guid,
void SetVesselStateOffset(Plugin const* const plugin,
char const* vessel_guid,
XYZ const from_parent_position,
XYZ const from_parent_velocity) {
plugin->SetVesselStateOffset(
guid,
CHECK_NOTNULL(plugin)->SetVesselStateOffset(
vessel_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) {
XYZ VesselDisplacementFromParent(Plugin const* const plugin,
char const* vessel_guid) {
R3Element<Length> const result =
plugin->VesselDisplacementFromParent(guid).coordinates();
CHECK_NOTNULL(plugin)->
VesselDisplacementFromParent(vessel_guid).coordinates();
return {result.x / Metre, result.y / Metre, result.z / Metre};
}

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

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

XYZ CelestialParentRelativeVelocity(Plugin* plugin, int const index) {
XYZ CelestialParentRelativeVelocity(Plugin const* const plugin,
int const celestial_index) {
R3Element<Speed> const result =
plugin->CelestialParentRelativeVelocity(index).coordinates();
CHECK_NOTNULL(plugin)->
CelestialParentRelativeVelocity(celestial_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,92 @@ extern "C" DLLEXPORT
void InitGoogleLogging();

// Exports |LOG(SEVERITY) << message| for fast logging from the C# adapter.

This comment has been minimized.

Copy link
@pleroy

pleroy Sep 21, 2014

Member

Comment that this evaluates the argument so it is less efficient than directly doing LOG(INFO).

This comment has been minimized.

Copy link
@eggrobin

eggrobin Sep 21, 2014

Author Member

Done.

// 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.

This comment has been minimized.

Copy link
@pleroy

pleroy Sep 21, 2014

Member

"given arguments" (many places in this file).

This comment has been minimized.

Copy link
@eggrobin

eggrobin Sep 21, 2014

Author Member

Googling "with the arguments given" yields

About 1,280,000 results

Googling "with the given arguments" yields

About 635,000 results

// 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** 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 celestial_index,
double const gravitational_parameter,
int const parent,
int const parent_index,
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,
int const parent);
void UpdateCelestialHierarchy(Plugin const* const plugin,
int const celestial_index,
int const parent_index);

// 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* vessel_guid,
int const parent_index);

// 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* const plugin,
char const* vessel_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,
char const* guid);
XYZ VesselDisplacementFromParent(Plugin const* const plugin,
char const* vessel_guid);

// Calls |plugin->VesselParentRelativeVelocity| with the arguments given.
// |plugin| should not be null. No transfer of ownership.
extern "C" DLLEXPORT
XYZ VesselParentRelativeVelocity(Plugin* plugin,
char const* guid);
XYZ VesselParentRelativeVelocity(Plugin const* const plugin,
char const* vessel_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* const plugin,
int const celestial_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* const plugin,
int const celestial_index);

// Says hello, convenient for checking that calls to the dll work.
extern "C" DLLEXPORT

This comment has been minimized.

Copy link
@pleroy

pleroy Sep 21, 2014

Member

Comment why this is here.

This comment has been minimized.

Copy link
@eggrobin

eggrobin Sep 21, 2014

Author Member

Done.

char const* SayHello();

} // namespace ksp_plugin
} // namespace principia

This comment has been minimized.

Copy link
@pleroy

pleroy Sep 21, 2014

Member

Can we #undef DLLEXPORT here?

This comment has been minimized.

Copy link
@eggrobin

eggrobin Sep 21, 2014

Author Member

Done, together with a

#if defined(DLLEXPORT)
#error "DLLEXPORT already defined"
#else
// ...
#endif

at the beginning.


#undef DLLEXPORT
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.