Skip to content
Pascal Leroy edited this page Mar 25, 2017 · 1 revision

Most KSP mods consist of some CLR DLLs that get loaded by KSP. Principia has most of its logic (in particular, all the numerical analysis) in a native library (ksp_plugin/) compiled from C++14, which is called from the C♯ layer (ksp_plugin_adapter/) via a P/Invoke interface. That interface is, for the most part, generated by a custom code generator (tools/) from protocol buffer descriptors (serialization/journal.proto). Those descriptors allow for journalling of anything crossing the interface; this is used for profile-guided optimization as well as debugging.

For serialization (saves), the C++ objects are serialized using protocol buffers (see the .proto files in serialization/), and the protocol buffer binary format is then written as a sequence of hexadecimal strings to the KSP save.

The rest of the codebase is mostly a series of C++14 template libraries, which come with their tests. Roughly in topological order,

  • base/ contains general utilities.
  • quantities/ is a strongly-typed library for physical quantities. The implementation uses binary64 (double) floating-point in SI units, but this is not exposed to the user, who explicitly multiplies or divides by units. Angles are dimensionful to obviate confusion between degrees and radians. Strongly-typed elementary functions are provided.
  • geometry/ deals with geometrical concepts useful for classical physics: strongly-typed Vectors of some Quantity with a strongly-typed dependency on the reference frame, a distinction between Vectors and Bivectors (also known as pseudovectors), a distinction between Vectors and Points (which live an affine space). It provides abstractions for changes of coordinates between reference frames (Rotation, OrthogonalMap, Permutation). Vector quantities useful for classical physics are named, e.g., Position, Velocity, AngularVelocity...
  • numerics/ provides various numerical utilities, with enough templatization to work with the aforementioned types. This contains some code with precomputed matrices generated by a Mathematica notebook.
  • integrators/ focuses specifically on numerical integration.
  • physics/ provides libraries to deal with a physical system under the influence of gravity: abstractions for bodies, trajectories, ephemerides, and reference frames defined from the bodies in the physical system, as well as some support for Kepler orbits and Jacobi coordinates.
  • astronomy/ contains libraries and data that have to do with the real world: our solar system, our timescales (support for date literals in TT, TAI, UT1, and UTC, where the type Instant counts TT). Time scale handling involves code generated from IERS tables by an awk script. Moreover, astronomy/ contains high-level tests of the above libraries for real-life astronomical scenarii: precession of the perihelion of Mercury, lunar eclipses...

In addition,

  • benchmarks/ contains benchmarks using (a fork of) https://github.com/google/benchmark/,
  • benchmark_automation/ is a C♯ utility used to run the benchmarks and parse their output,
  • coverage_analyser/ is a C♯ utility that interprets the output of the instrumented tests to yield coverage statistics,
  • stacktrace_decoder/ is a C♯ utility used to turn logs containing stack trace addresses and the DLL base address into something usable.
Clone this wiki locally