# FBC: NIGHT SHIFT — Technical Design ## Stack (locked) - **C++23** (GCC 13+; developed on GCC 16) - **CMake 3.15+** (developed on 4.3) - **raylib 6.2**, pinned via CMake `FetchContent` (`GIT_TAG 6.2`, link target `raylib`). 6.2 is the current release (Oct 2026) and fixed CMake-4.x build issues; builds GLFW from source (X11/GL dev headers required). raylib 6.x adds the Image/Draw API alignment (procedural textures) and skeletal model animation (`UpdateModelAnimation`, GLTF/IQM/M3D). S17 uses that path for the single player agent: `agent.glb` carries a 19-bone armature and five baked actions; `ModelBank` advances the clip with `GetFrameTime() * 60` and raylib CPU-skins it into the existing `actor.vs` (the shader deliberately has no bone attributes, so raylib's CPU fallback runs). The horde keeps shader-side procedural rigs, which stay one draw call per actor. - No other third-party deps until they earn their place. Authored level data is JSON; it is cooked into a small custom binary during the build and only that binary is loaded at runtime (see `docs/LEVEL_DATA_PIPELINE.md`). ## Repo layout ``` CMakeLists.txt assets/models/ # sculpted GLB actors + props/ OoP set dressing assets/shaders/ # actor, concrete, aura, bloom_*, post_fx assets/textures/ # concrete/ PBR set, actor/ lighting ramp LUT assets/blender/ # source .blend scenes tools/blender/ # actor_kit, build_enemies/props/materials/scene, build_lut docs/ # this is the design source of truth src/ main.cpp # CLI (--seed N), window, fixed-tick loop, bloom render targets core/ # NO raylib includes here. math, rng (PCG32), events game/ # NO raylib includes here. simulation input.hpp # InputState contract (filled by main from raylib) corruption.* # RoR2-style difficulty coefficient + tier ladder player.* # movement, dash, stats enemies.* # archetypes, AI steering + separation, contact damage weapons.* # auto-fire, projectiles, targeting pickups.* # XP shards, magnet buffs.* # scene-wide buffs/debuffs (ECS-like) ritual.* # OoP ritual quest flow game.* # Game class: state machine (Playing/GameOver), fixed-tick update render/ # raylib lives here only (+ main.cpp) presenter.* # 3D diorama camera, actor draws, sparks, blob shadows, bars models.* # GLB bank + gradient-ramp actor shader + limb rig uniforms concrete.* # one merged triplanar PBR mesh for floor/curbs/pillars layout.hpp # shared pillar/open-room anchors for concrete + presenter camera_tuning.hpp # live FOV/height/forward dev slider values aura.* # reusable SDF ground waves for tier-ups / bosses ui.* # HUD, death screen, camera dev slider ``` ## Architecture decisions 1. **Sim/render split.** `core/` and `game/` never include raylib; `main.cpp` fills an `InputState` and the presenter reads the world. This keeps the sim portable (the planned `--headless --bot-runs` pacing telemetry), testable, and lets the presenter be swapped (pure 2D, full 3D) without touching game logic. The sim is a floor-plane (Vec2) game regardless of how it is drawn. 2. **Fixed 60 Hz logic tick** with a render-rate accumulator in `main.cpp`. 3. **Deterministic seeded RNG (PCG32)** in the sim; presentation-only randomness (screen shake) uses raylib's RNG and cannot touch game state. 4. **Event queue** (`EventQueue`, consumed and cleared by the presenter each frame): kills, hits, player damage, tier-ups -> VFX / SFX / screen shake / damage numbers. 5. **Object pooling** (`core/pool.hpp`, dense swap-remove pool — no alloc churn after warmup, O(alive) iteration) for projectiles, enemies, shards. 6. **Spatial hash** (`core/spatial_hash.hpp`, sorted-bucket, zero per-insert allocation) for enemy separation and projectile collision at horde scale. 7. **Credit-based spawn Director** (`game/director.*`) with RoR2's "too cheap" rule and the elite-bank rule (implemented in M2). 8. **Data pipeline, not code-generated data.** Levels are authored in JSON, validated and cooked to a deterministic binary by `level_tool --bake` during the asset build step, and the client loads only the binary. Debug/editor builds may read JSON directly for hot-reload; release builds cannot. ## Rendering pipeline (hybrid) - `Camera3D` three-quarter view following the player (default fovy 55 / height 16 m / forward 15 m after the S16 critical-lens pass, all live-tunable from the HUD's CAMERA DEV panel), target clamped 8 m inside the arena curb so the unlit outer floor never dominates. - **One merged triplanar concrete mesh** (`concrete.*`) for floor, curbs, pillars and door frame, sharing one tileable 2K PBR set from `build_materials.py`. - **Sculpted GLB actors** (`models.*`, `assets/models/`) lit by a gradient-ramp shader with faction rims. The horde uses a procedural limb rig (`uRigMode` 1 humanoid, 2 blob, 3 crystal) — no skeletons, no extra draw calls. The single player agent instead has a Blender skeleton and baked actions, CPU-skinned by raylib. Hiss actors and the agent get a cheap expanded-backface ink outline. - **Hard shadow map** (`render/shadow_map.*`) — one 2048² depth-only FBO built from rlgl primitives (raylib 6.2 has no shadow API). An orthographic light camera follows the player with texel snapping; the caster pass reuses the environment/actor vertex shaders with a depth-only fragment shader so the procedural rigs match, and culls to the light frustum. `concrete.fs` and `actor.fs` do a single NEAREST depth compare (no PCF) with a slope-scaled bias, darkening only the direct term. Blob quads remain as contact shading. `--shadows off` disables the pass and the receiver lookup. - **Sparks / glows / world objects** are camera-facing billboards using one procedural glow sprite; damage numbers and health bars use `GetWorldToScreen`. - Post FX: scene into a full-res `RenderTexture`, half-res bright pass + separable blur for bloom, then `post_fx.fs` (VHS noise, mild aberration, red Hiss tint, teal/warm grade, vignette) keyed to the corruption coefficient. HUD is drawn into the same target so post FX applies to it too — aberration is kept low to preserve legibility. ## Conventions - `snake_case` files/functions, `PascalCase` types, `kConstant` for constants. - `#pragma once` headers; include paths relative to `src/` (`#include "game/game.hpp"`). - Compile clean with `-Wall` semantics; no warnings ignored globally. ## CLI - `--seed N` run seed (implemented). - `--screenshot ` saves a PNG of the framebuffer (optionally `--screenshot-at `, default 3 s); F12 saves one on demand (implemented — dev tool, works under Wayland where root-window grabs cannot see composited windows). - `--bot` kiting autopilot: seeks shards, repels enemies, dashes (implemented — validation tool and the seed of the M6 balance-bot). - `--no-damage` stress mode for horde/pacing captures (implemented). - `--headless --bot-runs N` pacing telemetry (planned M6).