cntrl/docs/TECHNICAL.md

5.6 KiB

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) — an upgrade path for animated bosses; current actors use shader-side procedural rigs instead, which keep one draw call per actor.
  • No other third-party deps until they earn their place. Data lives in C++ tables (JSON only when content volume demands it).

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, fixed-tick update, level-ups
  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
    aura.*        # reusable SDF ground waves for tier-ups / bosses
    ui.*          # HUD, Board Directive cards, death screen

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).

Rendering pipeline (hybrid)

  • Camera3D three-quarter view (fovy 48) following the player, target clamped inside the arena curb so the unlit outer floor never dominates the frame.
  • 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 and a procedural limb rig (uRigMode 1 humanoid, 2 blob, 3 crystal) — no skeletons, no extra draw calls. Hiss actors also get a cheap expanded-backface ink outline.
  • Blob shadows (flattened cylinders) — no shadow maps in raylib core; they ground the puppets without cost.
  • 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 <path> saves a PNG of the framebuffer (optionally --screenshot-at <sec>, default 3 s); F12 saves one on demand (implemented — dev tool, works under Wayland where root-window grabs cannot see composited windows).
  • --screenshot-on-levelup <path> captures the frame when the Board Directive cards appear (implemented — UI validation).
  • --bot kiting autopilot: seeks shards, repels enemies, dashes, auto-picks the first Directive (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).