Commit Graph
26 Commits
Author SHA1 Message Date
Dejvino 303f17c2a6 Forbid airlock-hive connection 2026-11-15 21:54:09 +01:00
Dejvino b38d5d4b56 Extract map-specific data into a generic MapSource interface
One interface (nd_mapsource.h) now owns everything map-specific: tiles,
rooms/doors/cameras, the network graph (nodes + edges with roles replacing
the hardcoded N_AIRLK/N_DOOR/N_HIVE indices) and the entity spawn list.
The scenario populates its structures once via selectMap() and never checks
which map is active.

- DemoMapSource: self-contained demo grid (moved out of the sketch), demo
  node/edge/spawn tables
- GenMapSource: adapts the random MapGenerator — now with L-corridors for
  guaranteed connectivity, doors that lead somewhere, airlock pad, terminal
  and crates (never on corridor tiles); network graph derived from the room
  chain, marine-first spawn list with droid patrols
- NetDeck.ino: all source branching removed; red trace follows the real
  active-link path (BFS HIVE->ROOT); reinforcement spawns near the blast door
- Tests: MapTest validates 50 generated runs + demo via the interface with
  an airlock flood-fill; new generated-map integration journey; test node
  handles resolve through the source (no hardcoded indices)
2026-11-15 18:21:35 +01:00
Dejvino 7b80854e1d Marines continue walking while firing 2026-11-15 15:41:50 +01:00
Dejvino 9c629b6561 All units have the same shooting distance to make it fair 2026-11-15 15:07:15 +01:00
Dejvino a6ea66d646 Denser encounter: camera nodes, wider garrison, thicker walls
- Map: 6 new wall pillars/stubs + 4 new cover crates; all load-bearing
  fixtures (blast door, airlock, terminal, LOS/fog test lines) preserved
- Network: 4 -> 7 nodes, 3 -> 6 edges; new Camera node type (C_CAMERA)
  sees farther (FOG_CAM_R=6 vs FOG_NODE_R=3) and draws a dotted sight
  ring when online; fog radius is now a per-node sight field
- Garrison: 8 -> 12 units (room-1 patrol, server-room guard, corridor
  patrol, turret on the door approach)
- Fix link slot/edge index conflation in linkOnEdge(): out-of-order
  routes (e.g. JUNC-CAM1 in slot 1) shadowed JUNC-DOOR with a permanent
  LINKING... refusal; NetLink now carries its edge id
- Tests: unit/fog_camera_sees_farther, unit/link_slots_dont_shadow_edges
  (verified failing against the old code)
2026-11-15 14:56:55 +01:00
Dejvino 8534bdc0b2 Slow down game and make beeps shorter 2026-11-15 13:24:06 +01:00
Dejvino aa517e7a97 Extract playBleep usages into dedicated functions with unified positive/negative confirmation 2026-11-15 12:25:32 +01:00
Dejvino 7df1a2d785 Fix short beeps silent on HW: i2s_zero_dma_buffer erased the unplayed DMA ring
The legacy I2S driver buffers i2s_write() data in a TX DMA ring
(8x64 samples = 64 ms @ 8 kHz) and hands a buffer back to i2s_write()
only after the DMA finished playing it. After the last queued event
the sound task called i2s_zero_dma_buffer(), which memsets the whole
ring instantly — erasing everything not yet played. Any sound <= 64 ms
was written into free ring space without ever blocking, so the zeroing
wiped it before the DMA reached a single sample: completely silent on
hardware. Longer tones force i2s_write() to block on a full ring,
pacing rendering to real-time playback — hence only long beeps were
audible, and the fade-envelope cap never moved the threshold. Every
game beep <= 80 ms (link-active 10, laser 30, sever 40, bleep/ICE 50,
feedback 80) sat in the dead zone. The emulator never showed it: its
i2s_write shim fed SDL directly and had no ring at all.

Fix: replace the instant zeroing with a paced silence purge — once the
queue drains, write one ring + one chunk of zero samples through
i2s_write(), reusing each DMA buffer only after the DMA played it. The
sound plays out fully and the ring then loops silence (still kills the
tail-replay bug the zeroing existed for). Keep the envelope cap at
total/4 so short tones keep a steady-state portion.

Emulator shim gains a TX DMA ring model (write/play cursors + bounded
DAC-emitted log) so the bug class reproduces headlessly: unit/
sound_short_tone_reaches_dac fails on the zero_dma code, passes on the
purge (A/B verified); shim_zero_dma_erases_unplayed pins model fidelity;
sound_long_tone_plays_out_fully guards against truncation. SoundEngine
gains a pumpOne() test seam and begin(spawnTask) for deterministic
driving. Full suite: 26 unit + 7 integration + 4 E2E, 0 failures.
2026-11-15 12:19:21 +01:00
Dejvino 8008b78db0 Fix reinforcement slot index after MAX_UNITS refactor; align E2E freeze-tint sampling 2026-11-15 11:06:33 +01:00
Dejvino 1dcc87d8d4 Fix trackball click: I2S MCLK was claiming GPIO0; emulator pin-ownership parity
Root cause (on device): sound_engine zero-initialized i2s_pin_config_t,
leaving mck_io_num == 0. i2s_set_pin() then claimed GPIO0 — an
MCLK-capable pin on the S3 and the trackball centre / BOOT line — as
its MCLK output. Verified on device with a diagnostic build: pin0 read
LOW at idle, exactly one latched FALLING edge, clicks never registered.

- sound_engine: set pins.mck_io_num = I2S_PIN_NO_CHANGE explicitly.
- NetDeck: register the trackball click on release with contact-bounce
  collapse (the proven CrtTerminal pattern); pollTouch re-arms when
  isPressed() stays true but getPoint() reports no points (stuck GT911
  IRQ on some units).
- Emulator parity (so this class of bug dies before flashing):
  GPIO-matrix pin-ownership model in the shim — i2s_set_pin() claims
  its pins, claimed pins are dead inputs (digitalRead LOW, no edges,
  loud WARNING on claim/ISR collisions); host pin writes go through
  emu::setPin/togglePin with an edge-accurate ISR latch (a full
  press+release pulse between dispatches no longer gets swallowed);
  E2E inits SDL_INIT_AUDIO so the I2S path actually runs there.
  Regression coverage: e2e/trackball_click (fails on the old engine),
  unit/shim_claimed_pin_is_dead_input,
  unit/shim_edge_survives_same_dispatch_pulse.
- Makefile: firmware step follows the sketch move (root platformio.ini,
  src_dir = src/netdeck).
- HW.md: new notes file for emulator-vs-hardware quirks and the
  on-device debugging recipe.

On-device verified: clicks register in both views (beacon drops, node
routing). Fast layer 23 unit + 7 integration green. Note: e2e
boot_and_controls + network_journey failures are pre-existing at HEAD
(reproduced on a clean stash before this change).
2026-11-15 10:24:30 +01:00
Dejvino 4645c7a1c6 Move utilities.h to src/netdeck and remove duplication from examples/NetDeck 2026-11-15 09:49:16 +01:00
Dejvino 01d3d192af current mode visualization 2026-11-15 09:45:28 +01:00
Dejvino ce668a8005 Refactor: replace hardcoded unit array size 7 with nd::MAX_UNITS
- Replace hardcoded  with  in NetDeck.ino (8 occurrences)
- Add  to nd_layout.h
- Update test expectations in unit_tests.h and integration_tests.h from units[6] to units[7] to match the new reinforcement slot indexing

This enables supporting more than 7 units in the future.
2026-11-15 09:30:37 +01:00
Dejvino 6c7572bfae Fog of war: LOS-derived current/historical visibility bitmaps + rendering
Replace the fading visibility[] stub with two bitmaps over the tile grid:
fogNow (visible this tick) and fogSeen (persistent historical memory),
re-derived each sim tick via revealLos() Bresenham raycasts from:
- each living marine's 8-tile sight window (= marine fire range, so the
  squad never shoots into darkness), and
- each online network node uncovering its connected tiles (3-tile window).

Rendering (renderMap): never-seen -> flat dark gray, historical ->
luma grayscale via gray565(), current -> full palette. Hostiles on
non-visible tiles are hidden in renderUnits. Ad-hoc revealTile() stamps
(marine step, door/HIVE links, hand-placed airlock tiles) removed; fog
refreshes on door toggle and scenario reset.

Tests: 5 new unit tests (initial reveal, wall blocking with face render,
historical persistence, node uncover/sever, gray565 channels) plus a
regression pinning fog sight >= marine fire range.
2026-11-14 23:26:04 +01:00
Dejvino 7ef629d5df Fix Frenzy.EXE: use tile coordinates instead of pixel positions for HIVE frenzy radius check 2026-11-14 23:11:36 +01:00
Dejvino 3cf17a9a5f Add basic sounds and bloops for NetDeck
- Add SoundEngine I2S audio renderer (TONE/SWEEP/NOISE)
- Add gameplay sounds: unit hit, unit death, door open/close, laser fire
- Add network sounds: ICE cracking, trace progress, link severed
- Add UI sounds: click confirm, key presses, view switch, FRENZY/BLIND
- Add network state sounds: node select, link build, ICE cracking
- Emulator: default to 960x720 window (3x scaling)
- Update STATUS.md with M4 done

All 21 tests pass (14 unit + 7 integration, 0 failures).
2026-11-14 19:01:50 +01:00
Dejvino 21d37486cf Emulator: migrate SDL2 -> SDL3
Port the shared emulator harness (all apps) to SDL 3.4 + SDL3_ttf 3.2:
- window creation without position args; renderer logical size via
  SDL_SetRenderLogicalPresentation(LETTERBOX); SDL_RenderTexture;
  SDL_SaveBMP_IO frame dumps
- SDL_EVENT_* event scheme, flattened SDL_KeyboardEvent, float mouse
  coords; clicks mapped with SDL_ConvertEventToRenderCoordinates, keeping
  the Xwayland global-state cross-check from 260a2b3
- audio shim on the stream API (SDL_OpenAudioDeviceStream +
  SDL_PutAudioStreamData) since SDL_QueueAudio is gone
- TTF_RenderText_Blended (explicit length); SDL3_ttf header layout
  handled via __has_include (Ubuntu installs under SDL3_ttf/)
- e2e freeze-tint pixel assertions updated to the committed
  diagonal-stripe pattern (stale since the freeze rework; pre-existing
  failures at HEAD under SDL2), sampled away from the freeze text

Full suite green: 14 unit + 7 integration + 3 E2E journeys, 0 failures.
MissileCommand, MiataDrive, NetDeck build; CrtTerminal (missing sndBlip
declaration) and Lotus3 (sketch not in repo) fail identically at HEAD -
pre-existing, out of scope.
2026-11-14 17:03:30 +01:00
Dejvino 396731da9b Freeze mode: diagonal-stripe tint with color-key transparency
- Replace static horizontal scanlines with diagonal-stripe 8x8 sprite pattern
- Color-key transparency (ND_TRANS16 = 0x1F1F) leaves frozen game view visible
- Lower triangle of each 8x8 cell dims (freeze dim), upper triangle shows game view
- Stamp pattern tiled across viewport in 8x8 grid for 50/50 dim/visible coverage
- renderFreezeTint() called only when paused, integrated into render() pipeline
- All 7 unit tests pass
2026-11-14 15:39:56 +01:00
Dejvino cd688b8abe NetDeck: transparent color-key dither for the freeze tint
- stampImage16_P(): PROGMEM 16bpp stamp with color-key transparency
  (ND_TRANS16 pixels leave the destination untouched) — TFT_eSprite has
  no transparent pushImage variant, so it composites via drawPixel on
  both backends (sprite RAM on device, host framebuffer in the emulator)
- shim: pgm_read_byte/word/dword macros (flash is memory-mapped on
  host and ESP32 alike)
- pattern: 2px checker of black dots + transparent cells — half-visible
  dither, map/units stay readable underneath
- E2E now proves the transparency itself: wall pixels survive under
  transparent cells, dots render black, key color never rendered
2026-11-14 15:33:25 +01:00
Dejvino 83ec0217f4 NetDeck: freeze tint stamps a checkered 8x8 sprite pattern
- replace the nonexistent draw16bppSprite_P(NULL,...) call with
  pushImage(bx, by, 8, 8, checkered8x8): device = TFT_eSprite::pushImage
  (blits into the fb sprite), emulator = new shim TFT_eSPI::pushImage
  blit into the host framebuffer — same signature on both backends
- shim: define PROGMEM (no-op on host/ESP32, flash is memory-mapped)
- pattern data fixed into a real 2px checkerboard (black / 0x1F1F teal)
- E2E pixel assertions updated to the checker geometry

Verified: make netdeck (both targets) + full test suite, 0 failures
2026-11-14 15:24:42 +01:00
Dejvino a1d0730124 NetDeck: headless test runner — unit + integration suites, E2E as separate build
- emulator/tests/: harness.h (TEST/EXPECT framework, input + serial +
  framebuffer helpers), shim_globals.cpp (shim externs for test binaries,
  replacing main.cpp ownership)
- unit_tests.h (14): map/door/LOS/BFS/cover/link state machine/trace/
  spike/reinforcement/win/loss/reset — deterministic fixed-seed, sim
  stepped tick by tick
- integration_tests.h (7): keyboard->pollKeyboard->handleKey pipeline,
  beacon clicks -> squad movement, full network journey via clicks,
  hover-sever (incl. safe sever during trace), daemon gating
- e2e_tests.cpp (separate NetDeck-e2e build): real setup()/loop() journeys
  with device-pipeline input injection (boot grace, 0x55 keyboard, GT911
  tap, trackball ISRs), transcript + pixel assertions (HUD, freeze tint)
- shim SerialSim: opt-in transcript ring for test assertions (off by
  default, interactive emulator unchanged)
- make netdeck-test / -unit / -e2e (root) and make test / test-unit /
  test-e2e (emulator/); tests/README.md documents the structure
- STATUS.md: test-structure note

Verified: make netdeck-test -> 14 unit + 7 integration + 3 E2E, 0 failures
2026-11-14 13:02:41 +01:00
Dejvino b05d90bd12 NetDeck: move sketch to src/netdeck/ next to nd_layout.h
- src/netdeck/NetDeck.ino (git mv); the ../../src/netdeck include became
  a plain "nd_layout.h"
- examples/NetDeck/platformio.ini: src_dir = ../../src/netdeck, -I . for
  utilities.h (pio build green: RAM 8.6%, Flash 5.6%)
- emulator Makefile: NetDeck APP_DIR -> ../src/netdeck, extra -I for
  utilities.h; make APP=NetDeck + smoke verified green
- STATUS.md: notes the new source layout
2026-11-14 12:15:02 +01:00
Dejvino 5571ec8399 NetDeck M3: squad vs. droids — BFS marines, droid/turret AI, cover, win/loss flow
Combat half of the MVP vertical slice on the shared coordinate space:
- 2 marines (BFS to the player beacon, stop-and-fire hitscan), cover
  crates halve incoming hit chance, overhead + HUD HP meters
- patrol/stationary security droids, heavy droid + ceiling turret on the
  objective terminal; feedback spike now spawns a reinforcement droid
- win: marine reaches the terminal (BREACH SUCCESS); loss: SQUAD KIA;
  R resets either way; tracers dim in Network view
- firmware build fix: Arduino auto-prototypes break Unit& params
  (planPath/unitMove/inCover/acquireTarget now take unit indices)
- HUD fix: R:RESET no longer overlaps RESUME/PAUSE; daemon slots and
  SQUAD row spaced out
- STATUS.md: M3 section incl. scope note — BREACH SUCCESS is gated on
  the M4 FRENZY/BLIND daemons; loss path + reset verified headlessly
2026-11-14 12:13:33 +01:00
Dejvino 6d2f593bc5 NetDeck M2: sub-net graph, link routing, ICE crack, red trace + feedback spike
Implements MVP.md §1-§3 (network half of the vertical slice) on the shared
coordinate space:
- 3-room floorplan (airlock/corridor/server room) with blast door + terminal
- 4 nodes: AIRLK root - JUNC - DOOR_CTRL (on the door tile) / HIVE (3s ICE)
- animated link builds (dotted->solid, 1.5s plain / 3.0s ICE), reachability
  tree from AIRLK; links offline until the build completes
- DOOR_CTRL toggles the blast door; X severs the hovered link (ICE progress
  resets, trace cut short resets safely)
- cracking HIVE spawns a 4s red trace to AIRLK; arrival = feedback spike:
  links drop + 3s OVERHEAT lockout (TEMP bar)
- FRENZY/BLIND daemon slots gated on HIVE link (effects land in M4)
- R instant reset via resetScenario() (also fixes root-online init bug)
- boot straight into the paused encounter
- emulator: --tap "x,y@frame" and repeatable --type "text@frame" for
  headless scenario testing

Verified headlessly: full trace->feedback run, safe sever, all gating
messages, reset; visual dumps inspected. Spec: src/netdeck/MVP.md.
2026-11-14 11:23:37 +01:00
Dejvino 3dcafa25e7 NetDeck M1: hardware sandbox — full-frame sprite rendering + firmware build
- render into a full-frame RAM second buffer (TFT_eSprite/PSRAM on device,
  SDL shim framebuffer in the emulator) and push to the ST7789 as one
  continuous SPI stream per frame (MiataDrive anti-tearing pattern)
- keyboard stale-byte flush at boot end; device-trackball constants branch
- examples/NetDeck/platformio.ini: self-contained firmware build
  (pio run -d examples/NetDeck), ESP32-S3 compile verified
  (RAM 6.7% / Flash 5.5%), binary at firmware/NetDeck_M1_261114.bin
- STATUS.md: M1 tracker + on-device flashing checklist
- IDEAS.md: capture map-scroll and companion-app ideas
2026-11-14 11:04:24 +01:00
Dejvino 2bfd6c6428 NetDeck M0: emulator sandbox + design doc
- src/netdeck: DESIGN.md (RTwP cyber-tactical ship crawler for T-Deck),
  STATUS.md milestone tracker, nd_layout.h shared constants
- examples/NetDeck: M0 sandbox — 40x24 ship floorplan and 8-node sub-net
  in one shared coordinate space (door nodes pinned to bulkhead door
  tiles); Cameras/Network view modes via P (network overlaid as dotted
  outlines vs dimmed ship + full graph); trackball cursor (edge ISRs +
  momentum); Space tactical freeze with CRT scanlines; 20 Hz fixed-step
  sim (pause-verified frame-identical); keyboard @ I2C 0x55 groundwork
  for M2-M4
- emulator: APP=NetDeck support + Tab key host mapping
- platformio.ini: NetDeck src_dir ready for firmware build
2026-11-14 10:37:35 +01:00