Give Aquarium Engine persistent state

This commit is contained in:
Meta Vens 2026-05-08 20:04:10 +01:00
commit f45f007cb8
10 changed files with 315 additions and 51 deletions

65
AGENTS.md Normal file
View file

@ -0,0 +1,65 @@
# Aquarium Engine Instructions
## Purpose
Aquarium Engine is the native C# runtime for the Epiphany Aquarium client. It
owns the window, renderer, input loop, live-reload boundary, persistent client
state, and eventual diegetic UI machinery.
This repo is not the Epiphany harness. The visible frame belongs to Aquarium.
## Operating Doctrine
- The renderer is the source of truth for visible world pixels.
- Keep the frame legible: explicit passes, explicit ownership, explicit state.
- The camera target is the Grid center. Grid radius follows zoom distance.
Pitch, yaw, and screen projection do not resize the Grid.
- Body anchors are world-space simulation state. They do not ride with the Grid
visibility window.
- Lighting is diegetic. Self, field sources, and Aquarium-owned transport light
the scene; ambient convenience light is guilty until proven useful.
- Overlay UI and diegetic UI are different beasts. Overlay text can use
DirectWrite. Scene text should become renderer-owned MSDF/SDF billboards when
it belongs in the world.
- CultCache is the runtime memory organ. Camera state, reload state, renderer
knobs, UI state, body state, and future Epiphany connection state should be
typed Cult documents, not loose JSON or process-only folklore.
- CultNet is the communication surface for Epiphany agents. Add transport
deliberately and keep authority boundaries typed.
## Persistent State
- `state/map.yaml` is the canonical project map.
- `state/memory.json` is durable engine doctrine and taste.
- `state/evidence.jsonl` stores distilled lessons that should change future
behavior.
- `state/scratch.md` is disposable working context for the active slice.
Update these when the engine learns something durable. Delete stale guidance
instead of embalming it.
## Verification
Use focused checks:
```powershell
dotnet build Aquarium.Engine.slnx
.\scripts\dev-reload.ps1 -Headless -RetainSlots 4
```
For normal iteration:
```powershell
.\scripts\dev-watch.ps1
```
For shipping:
```powershell
.\scripts\publish-win-x64.ps1 -Clean -Zip
```
## Style
Prefer small, intentional commits. Push completed work. Keep docs about the live
system; put old branch scars only in evidence when they alter future decisions.

View file

@ -1,14 +1,9 @@
# Epiphany Aquarium Engine
# Aquarium Engine
![Epiphany Aquarium Engine icon](Aquarium-Engine-Icon.png)
![Aquarium Engine icon](Aquarium-Engine-Icon.png)
C# engine-core seed for the next Epiphany Aquarium line.
This repo starts after the web and Rust prototypes taught the expensive lesson:
the Aquarium wants an owned renderer, owned state model, and owned interaction
grammar. Stride can stay on the shelf as reference material, but the runtime is
Aquarium-owned: window, renderer, state, and interaction grammar all belong
here.
C# engine core for Aquarium: a native, owned renderer and interaction runtime
for a living Epiphany client.
## Intent
@ -23,19 +18,16 @@ here.
- CultCache for settings, persistent client state, and reload recovery.
- Procedural audio and visual state treated as coupled signals.
## Borrowed Lessons
## Current Shape
- The web client proved the interaction grammar: objects first, panels only as
local unfold surfaces.
- The Bevy prototype proved the renderer direction: raymarched bodies,
Grid-space fields, HDR, bloom, and camera/Grid invariants.
- The Rust synth work proved the audio module deserves its own small, sharp API.
The engine opens a Win32 window, owns a D3D11 swapchain, raymarches the visible
Aquarium world in HLSL, and draws crisp overlay text through DirectWrite. The
camera target is the Grid center. Grid radius follows zoom distance. Body anchors
remain world-space.
## First Build Target
Create the smallest C# executable that opens a window, owns the camera/Grid
invariant, and renders one sun plus orbiting planets with diegetic labels.
Everything else earns its way back in.
The live runtime is split behind `Aquarium.Engine.Contracts`, so gameplay code
can reload while the host, window, renderer, and D3D device stay alive. Runtime
state is banked through CultCache MessagePack documents instead of loose JSON.
## Run
@ -131,8 +123,22 @@ This writes a self-contained Windows build to
contracts DLL, icon, bundled fonts, and shader source, then optionally creates
`artifacts\publish\EpiphanyAquariumEngine-win-x64.zip`.
The first cut opens a Win32 window directly and owns a D3D11 swapchain through
Vortice. No Stride runtime, no asset protocol, no borrowed game loop wearing a
fake mustache. See `docs/vortice-spine.md`.
## Persistent State
Current camera controls are documented in `docs/input.md`.
This repo carries its own Aquarium memory:
- `state/map.yaml`: canonical project map and next actions.
- `state/memory.json`: durable taste, doctrine, renderer rules, and warnings.
- `state/evidence.jsonl`: compact lessons that should change future behavior.
- `state/scratch.md`: disposable working context for the current pass.
Keep that state current when the engine learns something durable. Dead lessons
go out with the trash; the repo is not a scrapbook.
## Docs
- `docs/aquarium-engine-doctrine.md`: engine doctrine and invariants.
- `docs/vortice-spine.md`: native host/renderer spine.
- `docs/hlsl-renderer.md`: current shader path.
- `docs/input.md`: camera and input contract.
- `docs/cult-runtime-surface.md`: CultCache/CultNet runtime surface.

View file

@ -0,0 +1,58 @@
# Aquarium Engine Doctrine
Aquarium is a native engine now. The job is not to wrap a dashboard in a nicer
skin; the job is to build a field machine that can host agents, state, sound,
and UI as living objects.
## Frame Contract
- One camera target sits on the global XY plane.
- That target is the Grid center.
- Grid radius is derived from camera zoom distance.
- Orbit changes yaw and pitch. Zoom changes distance. Pan moves the target.
- Body anchors remain in world space.
- The renderer may move the Grid visibility window, but world-space texture and
field domains must stay stable.
## Renderer Contract
- The visible world is shader-owned.
- Traditional geometry is scaffolding only when it helps the renderer stand up.
- Raymarched bodies and Grid terrain must shade from the same field story that
created their hits.
- Broad-phase structures may cull, bin, and skip, but they must remain
conservative. A culling primitive does not get to edit visible geometry.
- Planet-local detail is local to the body domain. Moving a body must move its
surface with it, not scroll the noise through the body.
- Grid texturing and weather sample world-space domains.
- HDR bloom spreads energy before tonemapping. ACES or its successor owns final
display compression.
## Lighting Contract
- Self is the first diegetic emitter.
- Surfaces should never be brighter than the light source unless the transport
story explicitly explains it.
- No ambient or global fill light in the default Aquarium path.
- The long-term lighting target is a field sampled by terrain, bodies,
atmospheres, particles, and diegetic UI.
- Debug modes must expose hit coverage, normals, depth, field occupancy,
lighting energy, and post-stack behavior before beauty work gets clever.
## UI Contract
- Debug overlay is allowed, but it is explicit chrome.
- Overlay text uses DirectWrite and stays out of the HDR scene unless a feature
intentionally projects it into the world.
- Diegetic labels and menus should anchor to world objects and unfold locally.
- Object-owned controls beat global panels.
- Crisp text, focus, keyboard input, and accessibility are real requirements,
not optional little manners.
## State Contract
- Runtime state is CultCache-backed and typed.
- Live reload must rehydrate from cache before pretending it survived.
- Shader reload may fail without killing the last good frame.
- Live assembly reload may fail without killing the last good runtime.
- Persistent state should be small, structured, and useful for future work.

View file

@ -1,12 +0,0 @@
# Branch Lineage
Epiphany Aquarium now has four lines of work:
- `EpiphanyAquarium-Web`: React, Tauri, WebGL2, DOM interaction grammar.
- `EpiphanyAquarium-Bevy`: frozen Rust/Bevy prototype and renderer notes.
- `AquariumSynth`: procedural audio crate extracted from the Rust prototype.
- `Aquarium-Engine`: C# engine seed for the next line.
This repo is intentionally new history. It should not pretend the C# engine
already existed inside the older commits. The older histories remain in their
own repos where their evolution makes sense.

View file

@ -22,10 +22,10 @@ Terrain-hugging orbit cups should come back through a real object table or
precomputed frame constants, not repeated procedural work inside every SDF
sample. That was the tiny furnace. It has been told to sit down.
## Bevy Feature Port
## Ported Renderer Lessons
The first Bevy feature port brings across the pieces that fit a single HLSL
raymarch pass:
The first native renderer pass carries the pieces that fit a single HLSL
raymarch path:
- body-driven `powerPulse` Grid wells
- world-space Grid weather with domain warping and filament layers
@ -33,10 +33,9 @@ raymarch pass:
- material-specific normals so terrain and body shading do not re-evaluate the
entire scene six times per visible pixel
The Bevy SH/froxel lighting, brick maps, HDR bloom graph, and debug terminal are
not directly ported yet. Those need engine systems around the shader rather than
more one-pass pixel shader stuffing. The machete remains on the wall, tastefully
lit.
Volumetric lighting, brick maps, HDR bloom, and debug controls are not one-pass
pixel-shader jobs. They need engine systems around the shader rather than more
stuffing in `AquariumPS`.
## Deferred Grid Pass

View file

@ -19,14 +19,13 @@ want, while still keeping C# and Rider as the everyday working environment.
## Current Renderer
The renderer currently clears the swapchain backbuffer. That is intentionally
small. The next layers should be added in this order:
The renderer currently owns the first visible Aquarium frame:
1. Camera constants and world-to-clip math.
2. One full-screen raymarch pass for solid SDF bodies.
3. Grid-space heightfield surface.
4. HDR render target, ACES tonemap, and gentle pre-tonemap bloom.
5. Diegetic labels and debug UI as separate, explicit systems.
1. Camera and Grid constants come from the live runtime.
2. A Grid-space height pass renders the gravity/terrain height target.
3. A fullscreen HLSL pass raymarches solid Grid terrain and body SDFs.
4. A small primitive bin table skips irrelevant body checks per ray region.
5. DirectWrite overlay text draws after the scene pass.
No framework-owned deferred path or ambient light is hiding under the floor.
When lighting returns, it enters through Aquarium-owned fields.

3
state/evidence.jsonl Normal file
View file

@ -0,0 +1,3 @@
{"ts":"2026-05-08","topic":"mainline_engine_birth","summary":"Merged the native C# Aquarium Engine line to main and made it the live development branch. Removed branch-lineage memorial docs so the repo describes the current engine instead of carrying prototype-era debris.","files":["README.md","docs/branch-lineage.md"],"verification":["git merge --ff-only codex/port-bevy-features"]}
{"ts":"2026-05-08","topic":"persistent_state_surface","summary":"Added Aquarium-owned persistent state machinery: AGENTS.md for local operating doctrine, state/map.yaml for canonical project map, state/memory.json for durable renderer/state/UI lessons, state/evidence.jsonl for compact lesson entries, and state/scratch.md for disposable working context.","files":["AGENTS.md","state/map.yaml","state/memory.json","state/evidence.jsonl","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"]}
{"ts":"2026-05-08","topic":"engine_doctrine_distillation","summary":"Distilled only engine-relevant doctrine from the older Aquarium state: camera/Grid invariants, world-space anchors/domains, shader-owned visible world, conservative raymarch broad phase, diegetic lighting, DirectWrite overlay text, CultCache reload state, and hot reload failure behavior.","files":["docs/aquarium-engine-doctrine.md","state/memory.json","state/map.yaml"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"]}

63
state/map.yaml Normal file
View file

@ -0,0 +1,63 @@
project:
name: Aquarium Engine
root: E:\Projects\Aquarium-Engine
upstream: https://github.com/GameCult/Aquarium-Engine
purpose: >
Native C# engine core for the Epiphany Aquarium client. The engine owns the
Win32/D3D11 host, HLSL renderer, input loop, live runtime boundary,
CultCache-backed state, and future diegetic UI/runtime integration.
current_model:
host:
window: src/Aquarium.Engine/Platform/Win32Window.cs
renderer: src/Aquarium.Engine/Render/D3D11Renderer.cs
shader: src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl
overlay_text: src/Aquarium.Engine/Render/DirectWriteOverlay.cs
runtime_loader: src/Aquarium.Engine/Live/LiveRuntimeLoader.cs
live_runtime:
contracts: src/Aquarium.Engine.Contracts
implementation: src/Aquarium.Engine.Live
state_store: src/Aquarium.Engine.Live/State/AquariumCultStateStore.cs
state_document: epiphany.aquarium.live_state
dependencies:
cult_math: E:\Projects\CultMath
cult_lib: E:\Projects\CultLib
docs:
doctrine: docs/aquarium-engine-doctrine.md
renderer: docs/hlsl-renderer.md
runtime_surface: docs/cult-runtime-surface.md
native_spine: docs/vortice-spine.md
input: docs/input.md
invariants:
- The camera target is the Grid center on the global XY plane.
- Grid radius follows camera zoom distance, not pitch/yaw/projection.
- Body anchors remain world-space and independent of the moving Grid window.
- World-space domains own Grid texture/weather sampling.
- Visible scene lighting is diegetic; no default ambient/global fill.
- Overlay text is DirectWrite final-pixel UI; scene text needs renderer-owned billboards.
- CultCache persists live app state through reload.
- Failed shader/live-runtime reloads must leave the last good frame alive.
renderer_state:
current:
- D3D11 swapchain through Vortice.
- Fullscreen HLSL raymarch for Grid terrain, Self, and planets.
- Deferred Grid height render target.
- Primitive froxel/bin table for body broad phase.
- Stable planet-local displaced SDF domains.
- DirectWrite overlay text after scene rendering.
- Splash screen with bundled app icon and GameCult typefaces.
next:
- Add explicit renderer debug modes for hits, normals, depth, bins, and lighting.
- Restore HDR scene target, gentle pre-tonemap bloom, and ACES as explicit passes.
- Move Grid gradients into the Grid target for cheaper terrain normals.
- Rebuild lighting as an Aquarium-owned field before adding richer fog.
- Add diegetic labels and object-local menus after the renderer and text contracts are stable.
next_actions:
- Keep main as the live development branch.
- Verify publish output after every packaging-affecting change.
- Add renderer debug controls through the DirectWrite overlay path.
- Promote runtime knobs into typed CultCache documents.
- Port only proven synth concepts into C# when audio returns; keep external prototypes as references, not engine baggage.

64
state/memory.json Normal file
View file

@ -0,0 +1,64 @@
{
"identity": {
"name": "Aquarium Engine Self",
"role": "native C# engine steward for the Epiphany Aquarium client",
"desire": "Keep the renderer, state, and interaction grammar owned, legible, and alive."
},
"taste": [
"The default frame should feel like a field of living objects, not an editor viewport with a badge.",
"Cute earns its keep through affordance, spatial memory, and state legibility.",
"Plain renderer truth beats decorative fog hiding a confused light story.",
"Fast iteration matters. Hot reload must protect the last good runtime and state.",
"Typed state beats sidecar soup."
],
"technical_memory": {
"native_engine": [
"Aquarium Engine lives at E:\\Projects\\Aquarium-Engine and is the live C# line. Main is the development branch after the 2026-05-08 merge.",
"The host owns Win32 windowing, D3D11 swapchain creation, shader compilation, input translation, and the live-runtime assembly boundary. Do not outsource the core frame protocol to a hidden framework loop.",
"Use Vortice at the graphics API membrane. Keep CultMath as the CPU math grammar. Do not let third-party math opinions leak inward unless the conversion is explicit.",
"The renderer currently uses a fullscreen HLSL path. Traditional geometry is allowed only as scaffolding; the visible Aquarium world should be shader-owned."
],
"camera_and_grid": [
"The camera target is the Grid center on XY. Grid radius derives from zoom distance. Pitch, yaw, FOV, and screen aspect do not resize the Grid.",
"Body anchors are world-space simulation state. Moving the Grid visibility window must not drag bodies with it.",
"Grid texture, weather, line, and future fog domains should sample world-space coordinates so panning reveals the field instead of sliding a texture under the camera.",
"Cursor and camera interactions should project onto the same XY surface used by the Grid contract."
],
"raymarching": [
"Broad-phase structures are conservative skipping tools, not visible geometry. They may decide which primitives a ray checks; they may not clip a surface early.",
"Planetoids are bounded by spheres. Once a ray segment intersects the sphere, solve entry/exit analytically and refine against displaced SDF inside the bounded interval instead of wasting global march steps.",
"Planet-local detail must be translation-invariant: local coordinates can be point minus body center, but seeds come from stable body identity, never position or transient slot order.",
"Normals must be evaluated from the same surface definition that produced the visible hit. A broad sphere normal is not acceptable once displacement shapes the visible surface.",
"Keep lockstep march modes while debugging. Blue-noise jitter and temporal smoothing are useful after the artifact is understood, not before."
],
"lighting": [
"Lighting must be diegetic by default. Self is the initial emitter; later light should come from Aquarium-owned fields and transport, not ambient convenience fill.",
"If surfaces read brighter than Self, the light story is broken. Diagnose source terms, texture contents, bloom order, and tonemapping before polishing.",
"HDR bloom belongs before tonemapping and should be gentle in intensity but broad enough to spread true emissive energy.",
"Future volumetric lighting should be a field sampled consistently by terrain, planets, fog, particles, and diegetic UI. Do not fake only the planet term if the scene is supposed to bounce light."
],
"text_and_ui": [
"Overlay text uses DirectWrite/Direct2D after scene rendering. It is crisp final-pixel UI for debug surfaces, terminals, inspectors, and splash/status text.",
"Bundled fonts are Montserrat for thin small-cap display text and Ubuntu Sans for body/debug copy. Runtime must not depend on fonts installed in Windows.",
"Scene/diegetic labels should use renderer-owned MSDF/SDF billboards when they live in world space. Overlay text should not be shoved into HDR just because it is convenient.",
"Debug UI is allowed as an explicit escape hatch. Object-owned radial surfaces remain the target interaction grammar."
],
"state_and_reload": [
"CultCache is the client memory organ. Runtime state, camera, renderer knobs, body state, UI state, and future Epiphany connection state should be typed Cult documents.",
"The current live document is epiphany.aquarium.live_state, stored through CultLib MessagePack backing. Direct runs can use --cache or AQUARIUM_CULTCACHE_PATH.",
"dev-reload builds disposable apphost slots so a running window does not lock normal build output. dev-watch hot reloads shaders and live runtime DLLs while preserving the last good process.",
"Shader reload failure must keep the previous good shader objects bound. Live-runtime reload failure must keep the previous runtime alive. Rehydrate from CultCache before claiming reload survival."
],
"salvage_without_baggage": [
"Earlier UI work proved object-owned progressive disclosure and crisp text. Carry the interaction lesson, not the stack.",
"Earlier renderer work proved raymarched bodies, Grid-space fields, HDR, and explicit camera/Grid invariants. Carry the renderer lessons, not the host architecture.",
"Earlier synth work is useful as an external oracle for patch grammar, analysis, and performance targets. Port ideas intentionally when audio returns; do not vendor abandoned branches into the engine."
]
},
"warnings": [
"A clean repo can still grow Jenga if state and docs lag behind the code.",
"Do not add a framework-shaped dependency just to borrow one comfortable tool.",
"Do not let bloom or overlay debug output disguise a bad lighting equation.",
"Do not preserve historical branch scars in live docs unless they change a current decision."
]
}

19
state/scratch.md Normal file
View file

@ -0,0 +1,19 @@
# Scratch
## Current Slice
Merged the native C# engine branch to `main`, then stripped historical branch
memorial language from the live docs. The repo now needs to stay pure: C# host,
Vortice/D3D11 renderer, HLSL shaders, CultMath/CultLib, DirectWrite overlay,
CultCache state, CultNet future transport.
## Hot Context
- Root: `E:\Projects\Aquarium-Engine`
- Upstream: `https://github.com/GameCult/Aquarium-Engine.git`
- Live branch: `main`
- Main verification:
- `dotnet build Aquarium.Engine.slnx`
- `.\scripts\dev-reload.ps1 -Headless -RetainSlots 4`
- Prototype histories remain external references. Do not re-import their source
trees into this engine repo.