Cosmic

C++20 OpenGL 2D Game & Simulation Engine

The Cosmic engine running a live scene
The Cosmic engine host running a client plugin
View on GitHub




Built With Cosmic

Example Projects

Cosmic is proven by what runs on top of it — from the canonical template that every project starts from, to a live telemetry dashboard for a real combat robot. Expand a project to read how it works.

The Template Project preview
RenderingECSParallel PhysicsTelemetry

TemplateProject is a root manager Layerthat owns a set of child “mode” layers and switches between them:

  • TemplateRenderLayer — material + shader + camera demo (animated, time-driven).
  • TemplateSpriteLayer — sprite-sheet + ECS demo.
  • TemplateRenderBenchmarkLayer — instanced-rendering stress test.
  • BallPhysicsSystem — a ParallelSystem example running ball physics across worker threads (the canonical parallel-pipeline demo).
  • TemplateTelemetryLayer — wires all five telemetry subsystems together for ~20 simulated agents (record → export → replay → live charts → click-to-inspect).

It is the reference for time management, the composite-layer architecture, ECS integration, parallel physics, and telemetry — and it documents the “double-tick trap” pitfall.

View on GitHub ↗
Shear Force Telemetry App preview
Serial / ESP32Live TelemetryRecord & ReplayRobot Visual

A single Cosmic plugin layer that:

  1. Connects to an ESP32 microcontroller over a Bluetooth-SPP COM port using Cosmic::SerialPort.
  2. Parses framed, checksummed raw KISS telemetry packets tagged Right / Left (one ESP32 reads two drive ESCs on separate UARTs) and decodes them to engineering units on the PC (voltage, current, eRPM, motor RPM, wheel speed in mph, power) — so the conversion constants (motor pole pairs, gear ratio, wheel diameter, slip factor) can be tuned live in the UI without reflashing.
  3. Feeds both sides into the engine telemetry stack: DataRecorder → CSV + .bin export → DataPlayer replay.
  4. Overlays Right (red) vs Left (blue) for every channel in a live/replay dashboard, plus a single-side drill-down panel.
  5. Drives a differential-drive robot visual on a top-down Cartesian map (auto-scaling grid, origin marker, trail) by integrating pose from the two wheel speeds, so you can watch the robot translate and turn.

Fault tolerance:the two sides are fully independent — if one ESC’s telemetry wire dies, that side is flagged (error note + red wheel) and the app keeps running on the surviving side.

Extras: ships ESP32 firmware plus a simulator sketch that synthesizes realistic dual-ESC telemetry over Bluetooth so the whole pipeline can be demoed with no ESC or robot required.

View on GitHub ↗



Overview

What is Cosmic?

Cosmic is a C++20, OpenGL-backed 2D game and simulation engine for Windows, built around a hot-reloadable plugin model: the engine compiles once into an executable, and each project you build compiles into its own .dll that the engine loads at runtime — so you iterate on your project without ever recompiling the engine.

But it isn’t just a toy renderer. Cosmic blends two worlds: a 2D engine (batch renderer, entity-component-system, materials and shaders, cameras, a multithreaded job system) and a real-time instrumentation platform (a telemetry stack that records, exports and replays data; serial-port hardware I/O; and live ImPlot charts).

That telemetry-and-serial combination lets it talk to real hardware and visualize it live — an uncommon capability for a personal engine, and the reason it has a genuine real-world application: instrumenting a real combat robot.

At a Glance
LanguageC++20
GraphicsOpenGL
PlatformWindows x64
ArchitectureHot-reloadable plugin DLL
UI / PlottingImGui + ImPlot
ECSEnTT
The Big Idea

Engine Host + Plugin Workspaces

Cosmic splits into two binaries. The engine host is a single .exe, compiled once. Each project is a separate client workspace — a .dll the host loads at runtime and can hot-reload without ever restarting.

Every project’s entry point is a single Layer subclass. You override only the hooks you care about — OnAttach, OnUpdate, OnFixedUpdate, OnImGuiRender, OnEvent— and export the layer from your DLL. The engine’s Launcherhas a New Project button that copies the canonical template, renames every file and class to your project, and generates a wired CMakeLists.txt and build.bat.

Cosmic plugin / host architecture diagram
Engine host (.exe) loads and hot-reloads client plugins (.dll)
See It Run
Video Coming SoonA screen capture of the engine running a live demo — telemetry recording, replay and the differential-drive robot visual.
Technical Details

Under the Hood

The engine is written from scratch in modern C++. These are its building blocks — the renderer, the ECS, the job system, and the telemetry stack that makes it a real-time data lab.

Headline Feature

Telemetry System

Five subsystems working as one. DataRecorder captures per-entity float channels (thread-safe, multi-entity); DataPlayer replays the binary log with seek + interpolation; the TelemetryPanel owns the replay lifecycle with a scrubbable transport bar and live ImPlot charts; and EntitySelection + EntityPicker add click-to-inspect via a world-space hit test. It records to CSV and a binary .bin.

Hardware I/O

Serial Communication

A Windows COM-port reader (SerialPort) running on its own thread — used to ingest live telemetry from microcontrollers such as an ESP32 over Bluetooth-SPP. This is what connects the engine to real hardware.

Hot-Reloadable Plugin DLLs

The engine .exe loads project .dlls at runtime — rebuild and reload a project without ever restarting the engine.

Layer System

Clean lifecycle hooks — OnAttach, OnUpdate, OnFixedUpdate, OnImGuiRender, OnEvent — plus composite, multi-mode layer support.

2D Batch Renderer

Renderer2D batches quads, lines and SDF circles into minimal draw calls and tracks render stats such as draw-call counts.

Instanced Rendering

A stress-tested path for drawing huge numbers of objects efficiently; the template ships an instanced-rendering benchmark layer.

SDF Circles

Crisp, resolution-independent circles via signed-distance-field shading rather than triangulated geometry.

Materials & Shaders

A Material is a typed uniform bag; a custom GLSL preprocessing system and a documented “shader contract” govern standard uniforms like u_ViewProjection, u_Time and u_ViewportSize.

Sprite Sheets

SubTexture2D addresses atlas sub-regions, making sprite-sheet rendering straightforward.

Entity-Component-System

Scene owns an EnTT registry with built-in TransformComponent, SpriteRendererComponent and TagComponent. Systems come in serial (System) and parallel (ParallelSystem) flavors; rendering groups by material bucket and sorts by depth.

Job System & Parallel Pipeline

A persistent thread pool (worker count = logical cores − 1) with ParallelFor helpers, plus a four-pass pipeline and automatic snapshot/commit via SystemQuery<T> so per-entity simulation runs safely across all cores.

Time & Timeline System

A global time-scale plus per-layer time-scales cascade through the update hooks — supporting pause, rewind (negative time scale) and a fixed-timestep pass for deterministic physics.

Camera System

An orthographic camera paired with a WASD + scroll-zoom controller.

Virtual File System

Path resolution with engine:// and project:// prefixes so assets and logs resolve correctly per project.

Framebuffer (FBO)

Render the scene to an offscreen texture so it can be composited inside an ImGui viewport panel.

Logging

CS_INFO / CS_WARN / CS_ERROR macros (spdlog); the log directory can be redirected into a project’s own asset folder.

Minimal Project
MyProject.cpp
#include <Cosmic.h>

class MyProject : public Cosmic::Layer
{
public:
    MyProject() : Cosmic::Layer("MyProject") {}

    void OnAttach() override            { /* create GPU resources, scene, systems */ }
    void OnUpdate(float ts) override    { /* per-frame logic + rendering */ }
    void OnFixedUpdate(float dt) override { /* fixed-step physics */ }
    void OnImGuiRender() override       { /* draw ImGui/ImPlot panels */ }
    void OnEvent(Cosmic::Event& e) override { /* handle input/window events */ }
    void OnDetach() override            { /* release resources */ }
};

A minimal Cosmic project is a single Layer.

Concurrency

The Parallel Pipeline

Parallel ECS systems run through a structured four-pass pipeline. Components are snapshotted up front, per-entity work fans out across the worker pool, and results are committed back on a single thread — so simulation scales across cores without data races.

Pass 01PrepareSnapshot each system’s components via SystemQuery<T>.
Pass 02ExecutePer-entity work runs in parallel across worker threads (cores − 1).
Pass 03MergeCommit results back into the registry on the main thread.
Tooling

Build System

ScriptUse
setup.batRun once per machine. Registers the COSMIC_SDK_DIR env var that every project’s CMake relies on.
build_all.batFull CMake reconfigure + compile of the engine and all projects. Use after cloning or adding a project.
build.batIncremental build — skips CMake reconfigure. Day-to-day iteration.
build_engine.batBuilds only the engine host.
build_all_release.batClean Release build for distribution.
Debug vs Release: Debug builds keep symbols and asserts with no optimization (for development); Release uses /O2 with no asserts (for distribution and benchmarking). The rule: never benchmark in Debug — it can be 5–10× slower. Outputs land in build/Runtime/Debug/ or build/Runtime/Release/.
View on GitHub

Note: the README in this GitHub repository goes significantly deeper than this page.