Principia Documentation
repository·master·Indexed 21 days ago
https://github.com/mockingbirdnest/principiaA Kerbal Space Program mod that implements realistic N-body and extended body gravitation, replacing the stock sphere-of-influence model. The documentation covers installation, building from source, adding new dependencies, the Ketchup workflow for updating upstream dependencies, and release procedures using the make_principia_release script.
What's inside Principia
- Principia is a mod for Kerbal Space Program (KSP) that replaces the stock game's 'sphere of influence' physics with N-body and extended body gravitation. In Principia, vessels are influenced by all celestial bodies simultaneously rather than being locked to a single body's influence. This allows for more complex and realistic mission profiles, particularly when used with mods like RealSolarSystem.
Understand the purpose of SP3 files in Principia
masterTheastronomy/standard_product_3directory contains satellite orbit files in the Standard Product 3 (SP3) format. In the context of the Principia project, these files are used specifically as test data to validate orbit processing or astronomical calculations.Add a new dependency to Principia
masterTo add a new external dependency (e.g., a GitHub repository) to the Principia ecosystem, follow these steps to set up the directory structure, MSVC solution, and CI/CD pipelines.
1. Directory and Repository Setup
- Decide on an organization name (e.g.,
Bar) and a component name (e.g.,foo). - Create the directory
Principia\Bar. - Inside
Principia\Bar, clone the repository:git clone https://github.com/Bar/foo.git - Create an MSVC directory:
cd Principia\Bar\foo && mkdir msvc. - Create a solution file at
msvc\foo.sln. - Copy
common.propsintomsvc\foo.props.
2. MSVC Project Configuration
- Create an Empty Project C++ named
fooinsidefoo\msvc. This results in the structurefoo\msvc\foo\...to prevent name clashes. - (Optional) If the component has benchmarks, create an Empty Project C++ named
benchmarksinfoo\msvc. - (Optional) If the component has tests, create an Empty Project C++ named
testsinfoo\msvc. - Unload all projects in the solution and edit their
.vcxprojfiles to include the following import (preserving existing GUIDs):<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup Label="Globals"> <VCProjectVersion>17.0</VCProjectVersion> <ProjectGuid>{...}</ProjectGuid> </PropertyGroup> <Import Project="$(SolutionDir)foo.props" /> <ItemGroup></ItemGroup> </Project> - Edit
msvc\foo.props:- Replace
the-include-directorywith the directory containing headers. - Replace
the-benchmark-projectwith the benchmark project name (usexxxif none). - Replace
the-test-projectwith the test project name (usexxxif none). - Remove imports under condition
PrincipiaBenchmarkProjectif not usingGoogle\benchmark. - Remove imports under condition
PrincipiaTestProjectif not usingGoogle\googletest.
- Replace
- Load All Projects and add header/source files via
Add > Existing Item....
3. Compilation and Linking
- Ensure the project compiles. You can use the
PRINCIPIAsymbol to condition code changes if necessary. - Ensure the project links. Add dependencies in the
testsandbenchmarksprojects to link against thefoolibrary.
4. Solution Filtering
- Save the solution as a Solution Filter:
Save As Solution Filternamedmsvc\foo.slnf. - Add
msvc\foo.slnftoSolution ItemsviaAdd > Existing Item.... - Edit
msvc\foo.slnfto remove non-production projects (benchmarks, tests, etc.).
5. CI/CD Pipeline Setup (GitHub Actions & DevOps)
- Create
.github\workflows\build.yamlin the component directory. Adapt it from an existing project (e.g.,Google\re2). - Update
envvariables and the artifact name tofoo. - Add a step to download the artifact in
build.yaml:- name: Download foo artifact uses: mockingbirdnest/actions/windows/download_artifact@main with: name: foo configuration: ${{ matrix.configuration }} directory: Bar - In Azure DevOps, add
PRINCIPIA_HEADERS_FOOandPRINCIPIA_MSVC_FOOto thePrincipiavariable group. - Clone existing pipelines for Windows, Ubuntu, and macOS. Update the
Get sourcesstep (repo/branch) andPublish Build Artifactsstep (CopyArtifactsContentsandPublishArtifactName). - For Ubuntu and macOS, create
foo\principia_make.shandfoo\principia_variable_overrides.shto handle builds. - Add a step in the Ubuntu and macOS pipelines to download the
fooartifact.
- Decide on an organization name (e.g.,
Assemble Linux and macOS artifacts into the release zip
masterAfter running the release command and pushing the new tag, the Azure pipelines will build Ubuntu and macOS releases for
x64andx64_AVX_FMA. Once complete (approximately two hours):- Download the artifacts from the Azure pipeline run by navigating to the tag's run, clicking the published artifact, expanding
Principia>Release. - Download the following files for all four pipelines:
principia_Linux-yyyyMMddHH-Mathematician-0-g*.tar.gzprincipia_Darwin-yyyyMMddHH-Mathematician-0-g*.tar.gz
- Extract the
.tar.gzfiles. - Move the extracted
LinuxandmacOSdirectories into the corresponding<root>\principia <mathematician> for 1.x.y.zip(and any other version-specific zip archives) created by the release script.
- Download the artifacts from the Azure pipeline run by navigating to the tag's run, clicking the published artifact, expanding
Build Principia on Linux
masterBuilding Principia on Linux is a best-effort process.
Prerequisites:
- Clone the repository:
git clone https://github.com/mockingbirdnest/Principia.git cd Principia - Install plugin build prerequisites:
unzip,wget,binutils,make,automake,libtool,curl, andcmake. - Install adapter build prerequisites:
msbuild. - Install Clang version 20 using the following commands:
wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh 20 all sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-20 200 sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-20 200
Build Steps:
- Install and compile third-party dependencies:
Do not proceed if this step encounters errors../install_deps.sh - Link KSP and Unity assemblies. Principia expects these in a directory adjacent to the
Principiadirectory (e.g.,../KSP Assemblies/1.12.5). - Run the build:
Note: If unit tests fail, the resulting binary may not be functional.make
./install_deps.sh make- Clone the repository:
How to report a Principia crash
masterIf Principia crashes (manifesting as a Windows dialog, a SIGABRT on Linux, or the game simply stopping), you must provide specific log files from the Principia directory.
Required Files:
- Navigate to
<KSP directory>\glog\Principia. - Locate the
FATALfile that matches the crash time (e.g.,FATAL.20230920-223637.6656.log). - Locate the
INFOfile created shortly before the crash (e.g.,INFO.20230920-223615.6656.log). - Attach both files in their entirety to the GitHub issue. Do not provide snippets; the full files are required for analysis.
Required files from <KSP directory>\glog\Principia: - FATAL.<timestamp>.log - INFO.<timestamp>.log- Navigate to
How to enable and use Principia Journaling
masterPrincipia includes a journaling mechanism to record interactions between KSP and Principia to help analyze complex bugs. If requested by developers, follow these steps:
- Open
Logging Settingsin the main Principia window. - Select
Record journal (starts on load)at the bottom left. - Perform a scene change to ensure journaling is active (verify
Journaling is ONappears at the bottom right of the Principia window). - Reproduce the problem (note: journaling may slow down the game).
- If successful, send the relevant
*.logfiles and theJOURNAL.*file found in yourglog\Principiadirectory.
CRITICAL: Deselect
Record journal (starts on load)when finished, otherwise your game will remain slow.Steps to enable journaling: 1. Open 'Logging Settings' 2. Select 'Record journal (starts on load)' 3. Change scenes to verify 'Journaling is ON' 4. Reproduce issue 5. Submit *.log and JOURNAL.* files from glog\Principia- Open
Build Principia on Windows
masterTo build Principia on Windows, ensure you have the following prerequisites installed:
- Visual Studio 2022 (version 17.14.23 or later) with C# and C++ support. Note: Visual Studio 2026 is not supported.
- Windows SDK 10.0.22621 (newer SDKs are not supported).
- .NET Framework 4.7.2 SDK (including the Targeting Pack).
Note on Visual Studio Editions: The solution includes a C# project named
coverage_analyserwhich requires the Enterprise edition. If you are using a different edition, you can still build and test the mod by right-clicking the project and selectingProject > Unload Project.Setup Steps:
- Create a
<root>directory. Ensure it does not contain subfolders namedPrincipia,KSP Assemblies, orGoogle. - Clone the repository into
<root>using Git PowerShell:git clone https://github.com/mockingbirdnest/Principia.git - Copy KSP 1.12.5 assemblies to
<root>\KSP Assemblies\1.12.5. - Run the rebuild script from
<root>:.\Principia\rebuild_all_solutions.ps1
Troubleshooting: If the build fails with error
C1060, the machine may be running out of resources. Try:- Reducing parallelism by changing the
/mflag in themsbuildcommand within the script (e.g., to/m:1or/m:2). - Increasing the size of the Windows paging file.
.\Principia\rebuild_all_solutions.ps1Report bugs and feature requests on GitHub Issues
masterUse GitHub Issues for reporting bugs (crashes or unexpected behavior) and requesting new features or improvements.
Guidelines for reporting issues:
- No support for older versions: You must upgrade to the latest version and verify the problem reproduces there before opening an issue. Issues for older versions will be closed.
- Do not use GitHub for usage questions: Use Discord for questions like "how do I...?".
- Do not append to existing issues: Unless you are experiencing the exact same problem, create a new issue. Do not add unrelated problems to an existing thread.
- Feature requests: Explain the problem you are trying to solve rather than proposing a specific technical solution (avoid the XY Problem).
Get help with Principia usage on Discord
masterFor general questions regarding how to use Principia, getting started, or basic guidance, use the Principia Discord channel.
Important:
- Discord is not for reporting bugs.
- Do not post logs on Discord; they are considered spam.
Prepare and run the Principia release command
masterBefore releasing, ensure that fingerprints for detecting/fixing the stock system are up-to-date, the release metadata (name, date, lunation number) is correctly set in the main window, and the Azure pipelines for Ubuntu and MacOS are passing (green).
All commands must be executed using GitHub for Windows git Powershell.
Use the
make_principia_releasescript to generate the base release archives. The script requires the version name, language code, timestamp, primary KSP version, and an optional list of additional KSP versions requiring separate builds.. make_principia_release "<Mathematician>" "<language>" "yyyyMMddHH" "1.x.y" @("1.u.v"…)Catch up dependencies with the Ketchup workflow
masterWhen the upstream dependency (e.g.,
google/master) has moved forward, use the following workflow to rebase your local changes on top of the latest upstream state. This process involves tagging the current state, resettingmasterto the previous baseline, pulling the new upstream changes, and rebasing your work via a temporaryKetchupbranch.Workflow Steps
- Tag the current state: Create a tag for your current
masterso you can return to it if needed. - Create a catch-up branch: Create a new branch named
Ketchupfrommaster. - Reset
masterto the previous baseline: Move your localmasterback to the commit where the last catch-up was applied (typically the commit matchinggoogle/master). - Pull upstream changes: Pull the latest changes from the upstream source (e.g.,
google/master) into your localmaster. - Rebase changes: Rebase your
Ketchupbranch onto the updatedmaster. - Verify and Fix: Ensure the project compiles and tests pass. You may need to:
- Update
propsfiles to use the correct language dialect. - Add or remove projects (use a GUID generator for new projects).
- Update project contents (use
build_projects_helper.ps1if available to regenerate Visual Studio XML).
- Update
- Update
master: MergeKetchupback intomasterand force push. - Cleanup: Optionally squash commits on
masterusing interactive rebase, but keep theKetchupbranch intact for future reference.
# 1. Tag current master git checkout master git tag master20210521 # 2. Create Ketchup branch git checkout master git checkout -b Ketchup # 3. Reset master to previous baseline git checkout master git log --oneline git reset --hard <commit> # 4. Pull upstream git pull google master # 5. Rebase work git checkout Ketchup git rebase master # 6. Update master git checkout master git merge Ketchup git push -f # 7. Optional: Squash commits on master git rebase -i <commit>- Tag the current state: Create a tag for your current