Engine: - SdlContext and Window: RAII, throwing constructors, non-movable - FrameClock (real time, clamped dt) and SimClock (fixed 1/60 s steps, speed 0 = planning phase, backlog capped per frame) - Application owns them in lifetime order, exposes EngineContext, and runs the fixed-timestep loop; AppConfig::FromArgs parses --frames, --seed and --fullscreen - Temporary window-surface fill so Wayland maps the window until RenderDevice lands in step 2 Build: - Split into the siege_engine static lib and the siege_deck exe - check_engine_deps fails the build if Engine/ includes Game/ - ctest smoke test: siege_deck --frames 30 on the offscreen driver - siege_tests on Catch2 v3.15.3 (nixpkgs + CPM pin), with SimClock, FrameClock and AppConfig tests Docs: - Decision Log: error handling split, Catch2 for unit tests - Build Order step 1 done; Engine Overview, Main Loop and Time and README updated to match - AGENTS.md with build, conventions and gotchas for coding agents - .gitignore: .mcp.json (local CLion MCP port) and Obsidian's workspace.json (tab/pane state), now untracked Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
114 lines
5.1 KiB
Markdown
114 lines
5.1 KiB
Markdown
# siege-deck
|
|
|
|
A from-scratch tower defense deck-builder in C++26 on SDL3
|
|
|
|
## Getting started
|
|
|
|
With direnv:
|
|
|
|
```sh
|
|
direnv allow # loads the devShell on cd
|
|
cmake --preset debug
|
|
cmake --build --preset debug
|
|
./cmake-build-debug/bin/siege_deck
|
|
```
|
|
|
|
Without direnv, prefix commands with `nix develop --command`.
|
|
|
|
`siege_deck --frames N` renders N frames and exits. `ctest --preset debug` runs
|
|
the `siege_tests` unit tests, plus `--frames 30` headless (offscreen video
|
|
driver) as the `smoke` test, so it can run unattended from a script or CI.
|
|
|
|
## Layout
|
|
|
|
| Path | What it is |
|
|
|---------------------|------------------------------------------------------|
|
|
| `flake.nix` | devShells: `default` (clang), `gcc` |
|
|
| `CMakeLists.txt` | dependency pins, engine lib, game exe, tests |
|
|
| `cmake/Cpm.cmake` | CPM bootstrap — nixpkgs copy, else pinned download |
|
|
| `cmake/ImGui.cmake` | defines `imgui::imgui` from either nixpkgs or source |
|
|
| `Source/` | `Engine/` (`siege_engine`), `Game/`, `Main.cpp` |
|
|
| `Tests/` | `siege_tests` (Catch2), mirrors `Source/` |
|
|
| `Assets/` | copied next to the executable after each build |
|
|
|
|
## How dependencies resolve
|
|
|
|
Every dependency is declared once, as a `CPMAddPackage` call, and resolves two
|
|
different ways depending on where you build:
|
|
|
|
- **Inside the devShell** — `CPM_USE_LOCAL_PACKAGES=ON` makes each call try
|
|
`find_package` first, and all of them hit nixpkgs. Nothing is downloaded and
|
|
nothing is rebuilt; configure takes under a second.
|
|
- **Anywhere else** (Windows, CI, a machine without nix) — CPM fetches and
|
|
builds each one from its pinned tag.
|
|
|
|
Both paths are pinned to the *same* version on purpose. A dependency that
|
|
differs between "on my machine" and "in the nix shell" is the class of bug
|
|
this arrangement exists to prevent, so bumping one means bumping the other —
|
|
or waiting for nixpkgs to catch up.
|
|
|
|
Two dependencies don't fit the pattern cleanly, and the comments in
|
|
`CMakeLists.txt` and `cmake/ImGui.cmake` explain why: Boost exposes
|
|
`Boost::type_index` only in the modular CMake build, so both sides target the
|
|
header-only aggregate `Boost::headers` instead; and Dear ImGui ships no
|
|
`CMakeLists.txt` upstream at all, so `cmake/ImGui.cmake` builds it by hand
|
|
when nixpkgs isn't supplying it.
|
|
|
|
## CLion
|
|
|
|
CMake reloads need the devShell environment, and CLion has to be told where to
|
|
get it. Once per machine:
|
|
|
|
1. **Settings → Build, Execution, Deployment → Toolchains**: add a System
|
|
toolchain (e.g. `siege-deck (nix)`), then **Add environment → From file**
|
|
and choose `cmake/clion-env.sh`. CLion sources that file before every CMake
|
|
reload, build, run and debug session, so all of them get the flake's
|
|
compiler, CMake, `CMAKE_PREFIX_PATH` and CPM settings.
|
|
2. **Settings → Build, Execution, Deployment → CMake**: enable the `debug` and
|
|
`release` profiles that come from `CMakePresets.json`, set their toolchain
|
|
to the one from step 1, and delete the plain `Debug` profile CLion creates
|
|
by itself. That profile shares `cmake-build-debug` with the `debug` preset.
|
|
|
|
The file loads the shell through direnv, so run `direnv allow` once in the
|
|
checkout first.
|
|
|
|
The `intellij-direnv` plugin can't stand in for this. It only merges variables
|
|
into Run/Debug configurations, and a CMake reload isn't one, so with the plugin
|
|
alone CLion configures with no nix environment at all. It also writes a
|
|
snapshot of nix store paths into every run configuration, which goes stale on
|
|
the next `nix flake update`. The toolchain environment already covers runs, so
|
|
the plugin isn't needed.
|
|
|
|
To see what CLion will inherit, sourced the way CLion does it (through your
|
|
login shell):
|
|
|
|
```sh
|
|
"$SHELL" -l -i -c 'source cmake/clion-env.sh 2>/dev/null; command -v cmake; echo $CXX; echo $CPM_CMAKE_PATH'
|
|
```
|
|
|
|
### Launching from a terminal
|
|
|
|
`nix develop --command clion .` also works, but only because two system-level
|
|
breakages were fixed in `~/homelab/hosts/terra/configuration.nix` — neither is
|
|
specific to this project, and both made every Toolbox IDE unlaunchable outside
|
|
the Toolbox GUI:
|
|
|
|
- `programs.nix-ld.libraries` was unset, so nix-ld's minimal default applied
|
|
and carried no X11, freetype, wayland or xkbcommon. The bundled JBR died on
|
|
`libX11.so.6: cannot open shared object file`.
|
|
- `services.envfs.enable` now serves `/bin` and `/usr/bin` from the caller's
|
|
PATH, so the `#!/bin/bash` shebang Toolbox writes into its shims resolves.
|
|
NixOS ships only `/bin/sh`, so those shims previously failed everywhere.
|
|
|
|
Both need a `nixos-rebuild switch` to take effect. This flake deliberately
|
|
carries no IDE wrapper of its own.
|
|
|
|
### clangd
|
|
|
|
The shell regenerates `.clangd` on every entry, pinning the compiler's real
|
|
system include paths. Without it clangd cannot find the standard library on
|
|
NixOS: those paths are injected by the cc-wrapper through `NIX_CFLAGS_COMPILE`
|
|
at compile time, and clangd only ever reads `compile_commands.json`, so the
|
|
build succeeds while every `#include <...>` goes red. The file is generated,
|
|
gitignored, and rewritten to match whichever shell you entered.
|