N body simulation
  • C++ 70.6%
  • C 29.3%
Find a file
jojers 7dfceae416 chore: refactor namespace and documentation
Refactored the classes and structs related to memory ownership and
transfer to the zor::core::memory namespace. They had clearly outgrown
their position in zor::utils as they're now the backbone of the engine
itself.

Also improved the README documentation as well as added some javadoc
comments here and there but tbh the code almost reads like english so
idk probably not needed
2026-04-24 00:33:50 +02:00
lib/imgui chore: Removed ImGui as submodule. Keep only relevant files 2026-04-19 14:38:32 +02:00
src chore: refactor namespace and documentation 2026-04-24 00:33:50 +02:00
test chore: refactor namespace and documentation 2026-04-24 00:33:50 +02:00
.gitignore Change shader to use SoA SSBOs instead of AoS VBOs 2026-02-11 22:35:02 +01:00
CMakeLists.txt chore: refactor namespace and documentation 2026-04-24 00:33:50 +02:00
imgui.ini refactor: embed shader compilation in viewport 2026-04-05 13:47:28 +02:00
README.md chore: refactor namespace and documentation 2026-04-24 00:33:50 +02:00
zorya.supp Added valgrind suppression file to suppress leaks coming from glfw, gtk and fontconfig (not my fault) 2026-03-01 18:59:09 +01:00

Zorya - C++26 Newtonian gravity engine with hotswappable backends

Zorya is a (soon to be) high performance modular N body newtonian gravity engine built in C++26. It (will) feature runtime switchable compute backends. The rendering is handled using OpenGL 4.5 with an ImGui overlay. It serves as a study piece in HPC, heterogeneous computing and GPGPU computing. As such, a conscious decision to implement the naive O(N²) method was made. Keeping a computationally heavy yet highly parallel algorithm as the baseline allows Zorya to properly showcase the throughput difference between a purely scalar implementation, SIMD on CPU and GPGPU. Of course, this also means that optimisations are left on the table in the spirit of fair benchmarking. Finally, Zorya also supports runtime precision swappning to showcase the advantages and disadvantages of float and double for throughput and numerical stability.

Build and run

Dependencies

  • CMake 3.31+
  • C++26
  • glfw
  • glew

Build instructions

Start by cloning the repo

git clone https://dawn.wine/jojers/Zorya.git

Set up cmake and compile

cd Zorya
cmake -B build && cmake --build build -j $(nproc)

Run the application with ./build/zorya [args]. If compiled with tests, run them with ./build/zorya_tests

Runtime arguments

Zorya supports several arguments to control the way the engine generates the system. It makes the distinction between a major body and a minor body. They can be interpreted as either planets and asteroids or solar systems and lone stars. It depends on what scale you want to imagine.

Toggle Type Default Effects
-c, --count Number 10 Number of major bodies
-r, --ratio Number 5 Number of minor bodies per major body
-O, --orbit Range 50:500 Width of the acceptable spawning area
-Mm, --major-mass Range 0.1:50 Range of masses that a major body can be
-mm, --minor-mass Range 0.01:0.1 Range of masses that a minor body can be

A range must be formatted as from:to. Each side of the range is optional and omitting it will infer the default value. Please note that only positive values are accepted for both numbers and ranges.

For reference, the central star object has a mass of 1000.

Compile options

Zorya also has a some options passed at the CMake initialisation step like so cmake -B build [args]

Option Type Default Effects
ZORYA_TESTS ON,OFF ON Toggle the build of the test executable