Plan-2026-11-24-primal-plus-plus-restart-design
Primal_Plus_Plus: the restart plan (design)
Date: 2026-11-24. Status: draft for the user's approval.
1. Intent
Chuck wants to redo the work of the Primal fork (113 commits since master, issues #1-#83) in a new repository,
UnflavoredMeson/Primal_Plus_Plus, to learn and understand every system by building it himself. Claude helps
(reviews, answers, checks, tooling) but doesn't drive. The fork's history has done the exploring: the restart takes
its answers as decisions from day one and follows a route without the detours.
The output of this work is a set of Forgejo issues in Primal_Plus_Plus: milestones for stages, one issue per
system, each with the why, the decision, what to read first, checkbox steps, a done-when list, what Claude can help
with, and one or two things to learn.
2. Goals, non-goals, anti-goals
Goals:
- Every issue can be done by Chuck in a few sessions, in order, without reopening a settled question.
- The route reaches today's state (
convert_editor, 2026-11-24) plus the open issues (#13 to parity, #33, #39, #52's rest, #60, #62-#68, #71-#77, #81-#83, #10, #15, #16, #24, #34, #46). - Each decision says where its evidence lives (a doc section or an old issue), so experiments aren't repeated.
Non-goals:
- Copying the old code across. The old repository is reading material; Chuck writes the new code.
- Recreating the old issue numbers or the
Tnnnames. - Re-running the experiments whose answers are recorded (C# scripting, Slang, EnTT/flecs, GLM/rtm, logging as a
module,
ExecuteIndirect, Avalonia/Uno/Qt). They appear as "read first", not as tickets.
Anti-goals (it fails even if the issues exist):
- Issues written as instructions for Claude ("run X, then Y") instead of for a person learning.
- Issues so detailed that they are the code; or so vague ("modernize the engine") that they decide nothing.
- A stage that needs a later stage's work to be tested.
3. Constraints
- Starting point: Arash Khatami's
master(the new repo'smasteralready holds it). His headers stay on his files. - Both machines and both backends stay: Linux (clang 23, GCC 16, CMake + Ninja, Vulkan) and Windows (MSVC v145, MSBuild, D3D12 + Vulkan).
- Every rule of
Docs/Preferences.mdholds from issue 1 (C++23 only, trailing return types,const,PRIMAL_API, no issue numbers in code comments, downloaded and pinned third-party code, ...). The first issue copies that file. - The repo is public: no personal paths, hostnames or tokens in issues.
- Chuck commits. Claude never commits in either repository.
4. Approaches (decided in the conversation)
- Where to start: from Arash's
master(picked), not an empty repo with his code as reference (longest, repeats his videos), nor an empty repo built straight to the final design (abstractions before their problems are felt). - Destination: today's state plus the open issues (picked), not today's state only, nor a trimmed route.
- Layout: milestones per stage + one issue per system (picked), not one large issue per stage.
- Editor: the C++/ImGui editor early, the WPF editor frozen on day one (picked), not WPF kept alive until a late editor stage (the actor and prefab UI would be written twice, as happened).
5. Decisions taken from the fork (the stumbles and the day-one answer)
| What happened in the fork | Day one in Primal_Plus_Plus |
|---|---|
| Port first, then style, casts, headers, tests, CI reworked onto it | Stage 0 is tooling; every later line is written under it |
| Vulkan copied D3D12 module by module (44% identical), unified in #3 | Shared CPU-side renderer modules first; D3D12 refit onto them; Vulkan written against them |
| Renderer had its own camera/light/item objects, later replaced by reading ECS components | ECS and render components exist before the renderer work; the renderer reads them from the start |
Scripts: REGISTER_SCRIPT → PRIMAL_SCRIPT → entity scripts removed for behaviors; game.bin v1-v5 |
Reflection generator, game scripts and actors/behaviors decided up front; one game.bin format, versioned from v1 |
| Editor: WPF → Avalonia → C++/ImGui; actor/prefab UI written in WPF C# first | WPF frozen and out of the build on day one; the C++ editor is the only one that gets features |
| Engine static, made a shared library at #59 | PrimalEngine shared library + EngineMain + PRIMAL_API in stage 1 |
| FBX SDK → ufbx; vcpkg → downloads; D3D11 IBL → Vulkan compute; vendored MikkTSpace → download | ufbx, pinned downloads, Vulkan-compute IBL from the first ContentTools issue |
| Logging tried as a module, reverted | Logging is a header; new self-contained systems (jobs, frame, shader packs) are modules |
ExecuteIndirect added, later removed |
Direct draws only |
utl::vector switch, free_list byte relocation, later fixed |
utl::vector only; free_list with stable blocks and live bits from the start |
std::to_underlying, enum class, std::expected added in a later pass |
Rules from stage 0; no pass needed (#4/#5 dissolve) |
#68: game code couldn't reach math functions |
The game API exposes math:: from the stage-1 math issue |
6. Two ordering changes against the conversation's outline (Claude's call, flagged)
The outline put Entities after the renderer. Moving Entities & reflection before Shaders/Renderer lets the
renderer read render:: components on its first day instead of being refit later (the fork's #3 step 2). It costs
nothing on the editor side: editor scenes hold actors only, so plain entities never need editor UI, and the editor
stage still comes right after the renderer, before actors. A second change: ContentTools (S5) comes
before the renderer, with a command-line importer, because nothing else makes test assets once WPF is out. The WPF editor isn't affected (frozen).
7. Stages and issues
Each stage is a milestone. Sizes: S (1-2 sessions), M (3-5), L (6+). "Evidence" points at Docs/Reference/ in the new
repo (section 9) and at old Primal issues.
S0 Foundation
- Repository conventions (S):
Docs/Preferences.mdcopied and trimmed to what applies,CLAUDE.mdfor the new repo, copyright headers,.clang-format(ufps +InsertBraces),.editorconfig,.git-blame-ignore-revs. - CMake build for Linux beside MSBuild (M): presets clang/GCC Debug/Release, C++23 (
cxx_std_23,stdcpp23, v145),-Werrorand/W4 /WX /permissive-,cmake/PrimalDependencies.cmake+.targetsfor pinned downloads, output inx64/<Config>/. Engine builds on Linux with a stub platform first. - clang-tidy at zero, casts out (M): repo
.clang-tidy,modernize-avoid-c-style-cast, Windows compile databases for Windows-only code (Tools/WindowsCompileDb), CLion shared profile. - Self-contained headers, no include cycles (S):
header_checktarget,check_include_cycles.py, sorted include groups. - Unit tests (S): doctest downloaded and pinned, one
UnitTestsexecutable in both build systems, CTest. - Logging (M):
primal::logheader,std::format, logger thread, console/file sinks, ring buffer,check_log_usage.py. Evidence:Docs/Multithreading.md(logging part), old #19. - CI on Forgejo Actions (M): Linux image (
Tools/CI/Dockerfile, published to the registry),ci.shjobs (build clang/GCC, tidy, checks, sanitizers), Windows runner. Evidence: old #14,Tools/CI/. - Windows VM for checks (S, optional helper):
Tools/WinVM/. Claude can do most of it; Chuck reviews. - Freeze the WPF editor (S): remove
PrimalEditorfrom the solution build, keep its folder as reference until the C++ editor reaches parity (S11). EngineDLL keeps only what the tools need until S6 replaces it.
S1 Platform and engine shape
- Platform detection and the Linux platform layer (M):
PRIMAL_PLATFORM_*, SDL3 window, events and input on Linux, Win32 native on Windows,PRIMAL_GRAPHICSbackend choice. - The engine as one shared library (M):
PrimalEngine.dll/libPrimalEngine.so,PRIMAL_APImember by member, hidden visibility on Linux,EngineMainstatic library,RUNPATH $ORIGIN. Evidence:Docs/Actors.md17. - Math behind
math::(M): own storage types inMathTypes.h, DirectXMath only inMath*.h,check_math_usage.py, the math functions in the game API. Evidence:Docs/Math.md6, old #6, #68. - Layers and the game API boundary (S):
check_layers.pywith the table,EngineAPI/public set,enum classstd::to_underlying,std::expectedrules,utl::vectoronly.
utl::free_listwith stable storage (S): blocks that never move, live bits, refused badremove(). Old #48.- Display scale and HiDPI (S): per-window scale on both platforms (old #15). Pointer/text/clipboard events come with S7.
S2 Core runtime
- Job system module
primal.jobs(L): own pool, no fibers,parallel_for, counters, TSan preset and CI job,PRIMAL_JOBS. Includesattach_thread()if the editor needs a foreign thread (old #72; likely not, the C++ editor renders on the frame thread). Evidence:Docs/Multithreading.md8-9. - Frame phases
primal.frame(M): sync point, game code, transforms, render; queued entity create/remove; lifetime rules (begin_play()/end_play()). Evidence:Docs/Multithreading.mdstep 6. - Spin before sleep (S, optional, measured): old #73, done after S6 gives a renderer to measure.
S3 Entities and reflection
- Archetype ECS (L): 16 KB chunks, queries, per-chunk change versions, queued structural changes, systems on
primal.jobs, 32-bit ids. Evidence:Docs/Ecs.md5, 7 (the EnTT/flecs benchmarks are reading, not a ticket). - Transforms as components with a hierarchy (M): six components +
Parent/HierarchyDepth, world-space short names,local_*, level-by-level update on jobs. Evidence:Docs/Ecs.md8. - Reflection generator
PrimalReflectGen(L): markers,.generated.h, CMake + MSBuild integration, one registry keyed by FNV-1a, field types incl.s64/u64,std::array/std::vector/std::string. Evidence:Docs/Reflection.md7. - Game scripts and the game library ABI (M):
PRIMAL_GAME_SCRIPT(),begin_library_load()/end_library_load(), game DLL exports nothing. Evidence:Docs/Ecs.md10,Docs/Actors.md17. - Render components (S):
render::MeshRenderer, the four light components,render::Camera, reflected. They exist before the renderer reads them.
S4 Shaders
ShaderCompilerToolat build time (M): DXC for DXIL and SPIR-V, shared HLSL folder,PSHB, up-to-date keys. Decided: HLSL + DXC (evidence: old #45, Slang numbers).- Single sources and the layout check (M):
CommonConstants.hlsli, the engine shader table,ShaderBindings.h, the SPIR-V reflection layout check. - Shader packs (M): manifests, variants, module
primal.shader_pack, Debug shader info. - Shader hot reload (M): background compile,
reload_shaders()rebuilding pipelines in place; the editor hook comes in S7. Known limit: no DXIL on Linux (old #46).
S5 Content tools
- ContentTools on both OSes (L): DirectXTex and stb_image downloaded, ufbx, MikkTSpace, Vulkan-compute IBL
(its own compute device, not the renderer), BC7 quick mode, static + shared library, unit tests on
UnitTests/Data/. Evidence:Docs/ContentTools.md6, old #38, #12. PrimalImportcommand-line importer (S): FBX/texture/primitive mesh to the engine's packed assets, so EngineTest and the renderer have content before the editor exists (the WPF editor made them in the fork).
S6 Renderer
- Shared CPU-side renderer modules, D3D12 refit (L): camera math, light sets, frame packet, frames in flight,
engine shader loading,
graphics::scene::prepare()reading S3's render components. Only D3D12 exists here, so this is a refactor with a working picture. Evidence:Docs/Renderer.md6-9. - Vulkan device (M): function loader (X-macro,
VK_NO_PROTOTYPES), instance/device, VMA, validation andvalidation_stats(), swapchain with FP16 scRGB. Evidence: old #18. - Vulkan content and descriptors (M): uploads, meshes, textures, materials, mutable-descriptor heap, push descriptors.
- Gpass on both backends (L): depth prepass, reversed Z, direct draws, render targets per surface,
render_frame(span<SurfaceFrame>)with one wait/submit/present. Evidence:Docs/Renderer.md10-11. - Lighting, light culling, post (M): tiled culling (
LightCullingTileSize), shared constants. - Parallel preparation and recording (M): jobs per surface and chunk, secondary command buffers, per-thread
pools; numbers recorded. Evidence:
Docs/Renderer.md12. - GraphicsTests on both backends (M): in-memory content, validation fails a Debug run, coverage, debug names and markers. Evidence: old #28.
- UI pass, offscreen surfaces, readback (M): what the editor needs; ImGui drawn through it. Evidence:
Docs/Editor.md9. - EngineDLL retired (S): shader compilation and hot reload become a library the tools and editor link.
S7 Editor shell (C++, Dear ImGui)
- ImGui in the engine (M): pinned docking build, platform adapter (pointer, text, focus, cursor, clipboard,
display scale),
EDITOR_UIEngineTest. - The
ui::widget layer and theme (M): Inter + Lucide, the look inDocs/Preferences.md, headless smoke test. - Shell (M):
Editor/layers, docking layout, log panel, project browser (open/new from templates), viewport on an offscreen surface with the editor camera, shader hot reload hook. - Project, scene and prefab files (M): the new editor's own formats (section 9, question 1).
S8 Actors and editing
- Actor runtime (L):
Actor,Part,Behavior,ActorRef/PartRef, spawn/destroy rules, ticking. Evidence:Docs/Actors.md18. - Engine parts (M):
MeshPart, light parts,CameraPartwriting S3's components.Docs/Actors.md19. - Actor reflection (S):
PRIMAL_ACTOR()/PART()/BEHAVIOR(), by-name spawning.Docs/Actors.md20. - Outliner, details, gizmos, undo/redo (L): details from reflection, ImGuizmo, commands merged during a drag.
- Prefabs (L): records, capture, default-part matching, overrides, Edit Prefab.
Docs/Actors.md21-22. - game.bin (M): one format for actors, prefabs and attachments, versioned; default directional light in new scenes (old #63's cause).
- Ambient light actors (S): IBL inputs on the ambient light part (old #64).
- Actor messaging (L, optional): mailboxes and events (old #65).
S9 Content in the editor
- Content browser and import (M): in-process import, thumbnails through readback, the asset packer in C++.
- Meshes and materials in built games (M): geometry and textures in the packed content (old #33, #63).
- Asset editors (M): geometry, texture, material.
- glTF import with fastgltf (M): old #39.
- Replace DirectXTex's encoders (L): old #81.
S10 Game code
- Loading the game library in the editor (M):
platform::helper, reload. - Build service (M): CMake + Ninja and MSBuild, toolchain detection, New Class dialog, project templates.
- Run and IDE integration (M): run the game as a process with its log; open in VS Code/Visual Studio/Rider (old #16).
- Game code tests (S): game projects test their behaviors (old #62).
- Game-defined log categories (S): old #34.
S11 Ship
- Packaging the editor (M): CPack zip/installer on Windows, tar.gz/AppImage on Linux, CI builds them.
- Game export and the monolithic build (L): staging folder, one static executable (old #60).
- Parity review and deleting the WPF editor (S).
S12 Later (each optional, each with its condition)
Render graph (#66), thin RHI (#67), pipeline caches on disk (#10), async uploads (#71), game UI on the UI pass (#82), user editor extensions (#83), HDR on KDE (#24), reference-image tests (#74), the asset scene in CI (#75), Wayland in CI (#76), GPU-AV run (#77).
8. Issue template
Why: what breaks without it; what it unlocks later
Decided: the decisions, each with its evidence link
Read first: old docs/issues, Arash's files on master
Steps
- [ ] 1. ... (tests first where it fits)
Done when: [ ] builds 0 warnings both OSes [ ] tidy 0 [ ] tests [ ] ...
Claude can help with: reviews, test cases, failure analysis, tooling, the Windows VM
Learn: one or two concepts, a line each
Labels: area/*, size/S|M|L, optional, bug. Milestones S0-S12. A pinned Roadmap issue lists the stages
and their issues in order.
9. Decided by the user (2026-11-24)
- File formats (S7.4): JSON text for project, scene and prefab files; imported asset data and game.bin stay binary. Library (Claude's call): nlohmann/json, MIT, one header, downloaded and pinned like doctest; it reads plainly, which suits learning, and these files are small.
- Evidence lives in the new repo: the old
Docs/are copied intoPrimal_Plus_PlusasDocs/Reference/(read-only history; scrubbed of personal paths and hostnames, since the repo is public). Issues link toDocs/Reference/<file>.mdthere. S0.1 adds them.
10. Left to the builder (the plan)
- Each issue's exact steps and done-when items, from this outline and the old docs.
- Labels, milestones and the creation script (Forgejo API, the token file, never printed).
- Issue order inside a stage as listed; numbering follows creation order.