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.
This commit is contained in:
+59
-9
@@ -73,9 +73,16 @@ int main(int argc, char **argv)
|
||||
{
|
||||
long maxFrames = -1;
|
||||
const char *dumpPath = nullptr;
|
||||
const char *typeStr = nullptr;
|
||||
int typeFromFrame = 30;
|
||||
int dumpEvery = 0;
|
||||
// scheduled screen taps: --tap "x,y[@frame]" (repeatable)
|
||||
struct Tap { int x, y, at, hold; bool fired; };
|
||||
static Tap taps[32];
|
||||
int nTaps = 0;
|
||||
// scheduled typing: --type "text[@frame]" (repeatable, chars ~40 ms apart)
|
||||
struct TypeEvt { const char *s; int at; };
|
||||
static TypeEvt typeEvts[16];
|
||||
int nType = 0;
|
||||
#ifdef EMU_APP_MISSILECOMMAND
|
||||
bool autoplay = false;
|
||||
#endif
|
||||
@@ -83,8 +90,28 @@ int main(int argc, char **argv)
|
||||
if (!strcmp(argv[i], "--frames") && i + 1 < argc) maxFrames = atol(argv[++i]);
|
||||
else if (!strcmp(argv[i], "--dump") && i + 1 < argc) dumpPath = argv[++i];
|
||||
else if (!strcmp(argv[i], "--dump-interval") && i + 1 < argc) dumpEvery = atoi(argv[++i]);
|
||||
else if (!strcmp(argv[i], "--type") && i + 1 < argc) typeStr = argv[++i];
|
||||
else if (!strcmp(argv[i], "--type") && i + 1 < argc && nType < 16) {
|
||||
// "text[@frame]": queue another typing event (chars ~40 ms apart)
|
||||
const char *s = argv[++i];
|
||||
int at = typeFromFrame; // legacy default via --type-at
|
||||
const char *atp = strchr(s, '@');
|
||||
char *copy = strdup(s);
|
||||
if (atp) {
|
||||
at = atoi(atp + 1);
|
||||
copy[atp - s] = '\0';
|
||||
}
|
||||
typeEvts[nType++] = { copy, at };
|
||||
}
|
||||
else if (!strcmp(argv[i], "--type-at") && i + 1 < argc) typeFromFrame = atoi(argv[++i]);
|
||||
else if (!strcmp(argv[i], "--tap") && i + 1 < argc && nTaps < 32) {
|
||||
Tap &t = taps[nTaps++];
|
||||
t.x = t.y = t.at = 0; t.hold = 0; t.fired = false;
|
||||
const char *s = argv[++i];
|
||||
sscanf(s, "%d,%d@%d", &t.x, &t.y, &t.at);
|
||||
if (t.at <= 0) t.at = 30; // "@frame" part optional
|
||||
t.hold = t.at + 120; // hold long enough that a frame-paced
|
||||
// pollTick (~34 ms apart) sees it
|
||||
}
|
||||
else if (!strcmp(argv[i], "--autoplay")) { emuAutoplay = true; }
|
||||
#ifdef EMU_APP_MISSILECOMMAND
|
||||
else if (!strcmp(argv[i], "--wave") && i + 1 < argc) emuStartWaveRequest = atoi(argv[++i]);
|
||||
@@ -231,21 +258,27 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
// --type: queue the string on the keyboard device like a human typing
|
||||
// (one char per --type-at start, ~40 ms apart in millis time, so the
|
||||
// sketch processes each key before the next arrives).
|
||||
// --type: queue the strings on the keyboard device like a human typing
|
||||
// (chars ~40 ms apart in millis time, so the sketch processes each key
|
||||
// before the next arrives; each event starts at its "@frame").
|
||||
// '\n' emulates Enter: press the trackball pin for one iteration.
|
||||
static const char *typeNext = nullptr;
|
||||
static int typePressPin = -1;
|
||||
static unsigned long lastTypeMs = 0;
|
||||
if (typeStr && frame >= (uint32_t)typeFromFrame) {
|
||||
static int curType = 0;
|
||||
if (curType < nType) {
|
||||
const TypeEvt &te = typeEvts[curType];
|
||||
if (frame >= (uint32_t)te.at) {
|
||||
if (typePressPin >= 0) {
|
||||
emu::pinLevels[typePressPin] = 1; // release the Enter press
|
||||
typePressPin = -1;
|
||||
}
|
||||
if (!typeNext) typeNext = typeStr;
|
||||
const char *typeEnd = typeStr + strlen(typeStr);
|
||||
if (typeNext < typeEnd && millis() - lastTypeMs >= 40) {
|
||||
const char *typeEnd = te.s + strlen(te.s);
|
||||
if (!typeNext) { typeNext = te.s; lastTypeMs = 0; }
|
||||
if (typeNext >= typeEnd) {
|
||||
curType++; // event finished
|
||||
typeNext = nullptr;
|
||||
} else if (millis() - lastTypeMs >= 40) {
|
||||
lastTypeMs = millis();
|
||||
if (*typeNext == '\n' || *typeNext == '\r') {
|
||||
typeNext++; // consume the Enter char
|
||||
@@ -256,6 +289,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Headless test mode: start the game, wander the crosshair, keep firing.
|
||||
#ifdef EMU_APP_MISSILECOMMAND
|
||||
@@ -272,6 +306,22 @@ int main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
// --tap: scheduled screen taps (left-button touch at x,y from frame N,
|
||||
// held ~40 iterations so the sketch's frame-paced poll sees it)
|
||||
for (int i = 0; i < nTaps; i++) {
|
||||
Tap &t = taps[i];
|
||||
if (!t.fired && frame >= (uint32_t)t.at) {
|
||||
emu::touchX = t.x;
|
||||
emu::touchY = t.y;
|
||||
emu::touchDown = true;
|
||||
t.fired = true;
|
||||
std::printf("[emu] tap %d,%d at frame %u\n", t.x, t.y, frame);
|
||||
} else if (t.fired && frame >= (uint32_t)t.hold) {
|
||||
emu::touchDown = false;
|
||||
t.hold = -1; // released; don't re-release
|
||||
}
|
||||
}
|
||||
|
||||
// fire any emulated interrupts triggered by the pin changes above
|
||||
emu::dispatchIsrs();
|
||||
|
||||
|
||||
+482
-199
@@ -1,32 +1,35 @@
|
||||
/**
|
||||
* @file NetDeck.ino
|
||||
* @brief NetDeck — Breach & Board: Milestone 1 hardware sandbox.
|
||||
* @brief NetDeck — Breach & Board: Milestone 2 — network graph & traces.
|
||||
*
|
||||
* Milestone 1 (DESIGN.md §7): the same M0 sandbox sketch prepared for the
|
||||
* T-Deck hardware. Rendering goes into a full-frame RAM sprite and is pushed
|
||||
* to the ST7789 as one continuous SPI stream (anti-flicker, see present());
|
||||
* the emulator draws straight into the SDL shim framebuffer instead.
|
||||
* Milestone 2 (DESIGN.md §7) implementing the sub-net half of the MVP
|
||||
* vertical slice (MVP.md §2/§3) over the shared coordinate space:
|
||||
*
|
||||
* - shared tactical view (320x192) + HUD bar, ONE coordinate space:
|
||||
* bulkhead doors and their network door nodes occupy the same spot
|
||||
* - two view modes over that space (`P` to switch, `Tab` as legacy alias):
|
||||
* C) Cameras — full top-down ship view, network overlaid as outlines
|
||||
* N) Network — ship dimmed underneath, full network graph on top
|
||||
* - fixed-timestep engine loop (20 Hz sim decoupled from ~30 fps render)
|
||||
* - trackball cursor with edge-ISR counting + momentum
|
||||
* - keyboard device @ I2C 0x55: Space = tactical freeze, P = view switch
|
||||
* - demo floorplan tile map + demo sub-net graph with packet flow
|
||||
* - 3-room floorplan (airlock / main corridor / server room) with one
|
||||
* interactive blast door and the objective terminal
|
||||
* - 4 hardcoded nodes in the same coordinate space:
|
||||
* [AIRLK] root (always online) - [JUNC] - [DOOR] / [HIVE] (3 s ICE)
|
||||
* the [DOOR] node sits exactly on its blast-door tile
|
||||
* - click an adjacent node to route a link: animated dotted line that
|
||||
* turns solid over 1.5 s (3.0 s when ICE-locked); X severs the hovered
|
||||
* link (everything beyond it drops, ICE progress resets)
|
||||
* - [DOOR] node (once online) toggles the blast door open/closed
|
||||
* - cracking [HIVE] spawns a red trace pulse: 4 s back to [AIRLK];
|
||||
* arrival = feedback spike (links drop + 3 s OVERHEAT lockout)
|
||||
* - HUD: [1:FRENZY] [2:BLIND] slots (effects land in M4), TEMP bar,
|
||||
* RESET (R); boot goes straight into the paused encounter
|
||||
*
|
||||
* Run on the desktop: make APP=NetDeck run (from emulator/)
|
||||
* Headless smoke test: make smoke APP=NetDeck
|
||||
*
|
||||
* Controls (emulator / device):
|
||||
* Trackball move cursor (snaps to tiles in Cameras, nodes in Network)
|
||||
* Trackball move cursor (tiles in Cameras, nodes/links in Network)
|
||||
* Enter / click trackball press / screen tap = primary action
|
||||
* Space toggle tactical freeze (time-stop + CRT scanlines)
|
||||
* Space toggle tactical freeze (starts PAUSED)
|
||||
* P (or Tab) switch view: Cameras <-> Network
|
||||
* 1-4 arm slotted exploit daemon (groundwork, flashes slot)
|
||||
* X / R / Q / E sever link / retreat / cycle (groundwork, logged)
|
||||
* X sever the hovered network link
|
||||
* R reset the scenario
|
||||
* 1 / 2 FRENZY / BLIND daemons (need an online [HIVE] link; M4)
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
@@ -38,19 +41,12 @@
|
||||
#include "../../src/netdeck/nd_layout.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Hardware
|
||||
// Hardware + full-frame rendering (M1 anti-flicker pattern)
|
||||
// ---------------------------------------------------------------------------
|
||||
TFT_eSPI tft;
|
||||
TouchDrvGT911 touch;
|
||||
static bool touchAvail = false;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Full-frame rendering — draw into a RAM buffer, push to the panel once per
|
||||
// frame (the MiataDrive anti-flicker pattern: thousands of small draw calls
|
||||
// racing the panel's scan-out cause tearing; one continuous SPI stream writes
|
||||
// each pixel exactly once). Emulator: the SDL shim framebuffer IS the second
|
||||
// buffer, so we draw straight into it.
|
||||
// ---------------------------------------------------------------------------
|
||||
#ifndef EMULATOR
|
||||
static TFT_eSprite fb(&tft); // full-frame 320x240x16 buffer (PSRAM)
|
||||
static TFT_eSprite *const GFXP = &fb;
|
||||
@@ -59,7 +55,6 @@ static TFT_eSPI *const GFXP = &tft;
|
||||
#endif
|
||||
|
||||
#ifndef EMULATOR
|
||||
// Push the finished frame to the ST7789 as one continuous SPI stream.
|
||||
static void present()
|
||||
{
|
||||
if (!fb.created()) return;
|
||||
@@ -80,96 +75,320 @@ enum ViewMode { VM_CAMERAS, VM_NETWORK };
|
||||
static ViewMode viewMode = VM_CAMERAS;
|
||||
|
||||
static uint32_t stateT0 = 0;
|
||||
static bool paused = false;
|
||||
static uint32_t simTick = 0; // 20 Hz deterministic ticks
|
||||
static uint32_t simAcc = 0; // fixed-timestep accumulator
|
||||
static bool paused = true; // MVP: boot straight into the paused encounter
|
||||
static uint32_t simTick = 0;
|
||||
static uint32_t simAcc = 0;
|
||||
static uint32_t lastFrameMs = 0;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Demo deck floorplan (40x24 tile grid; DESIGN.md §3 shared tactical view)
|
||||
// '#' wall '.' floor 'o' cover crate '+' bulkhead door 'A' airlock
|
||||
// Rooms: left hull (w/ Security), top-mid lab, bottom-mid hold (Power),
|
||||
// right server vault (Droid Hive). Bulkhead doors are network door nodes.
|
||||
// Floorplan (MVP.md §1): 40x24 tiles, 3 rooms
|
||||
// '#' wall '.' floor 'o' cover crate '+' blast door 'A' airlock 'T' terminal
|
||||
// Room 1 airlock (bottom-left), Room 2 main corridor (L-shaped middle),
|
||||
// Room 3 server room (right). The '+' door is the Room2/Room3 blast door.
|
||||
// ---------------------------------------------------------------------------
|
||||
static const char *const DEMO_MAP[nd::TILE_ROWS] = {
|
||||
"########################################",
|
||||
"#...........#.............#............#",
|
||||
"#..o........#.............#...o........#",
|
||||
"#...........#....o........#............#",
|
||||
"#..........+.............#............#",
|
||||
"#...........#.........o...#............#",
|
||||
"#.......o...#.............#.........o..#",
|
||||
"#...........#.............#............#",
|
||||
"#...........######+#######............#",
|
||||
"#...........#.............#............#",
|
||||
"#.o.........#.............#............#",
|
||||
"#...........#.............+............#",
|
||||
"#...........#..o..........#............#",
|
||||
"#...........#.............#............#",
|
||||
"#........o..#.............#.o..........#",
|
||||
"#...........#.............#............#",
|
||||
"#...........#........o....#............#",
|
||||
"#...........#.............#............#",
|
||||
"#..........+.............#......o....#",
|
||||
"#...o......#.............#............#",
|
||||
"#...........#...........o#............#",
|
||||
"#.A.........#.............#....o......#",
|
||||
"#...........#.............#............#",
|
||||
"#.........#.................#..........#",
|
||||
"#.........#.................#..........#",
|
||||
"#.........#.................#..........#",
|
||||
"#....o....#.................#..........#",
|
||||
"#.........#.................#..........#",
|
||||
"#.........#.................#..........#",
|
||||
"#.........#.................#.....T....#",
|
||||
"#...........................#..........#",
|
||||
"#...........................#..........#",
|
||||
"#.........#...o.............#..........#",
|
||||
"#.........#.................#..........#",
|
||||
"#.........#.................+..........#",
|
||||
"###########.................#..........#",
|
||||
"#.........#.................#..........#",
|
||||
"#.........#...........o.....#..........#",
|
||||
"#.........#.................#..........#",
|
||||
"#...........................#..........#",
|
||||
"#...........................#..........#",
|
||||
"#.........#.................#..........#",
|
||||
"#.........#.................#..........#",
|
||||
"#.A.......#.................#..........#",
|
||||
"#.........#.................#..........#",
|
||||
"########################################",
|
||||
};
|
||||
|
||||
static const int AIRLOCK_TX = 2, AIRLOCK_TY = 21; // breach entry tile
|
||||
static const int DOOR_TX = 28, DOOR_TY = 12; // the Room2/Room3 blast door
|
||||
static const int AIRLOCK_TX = 2, AIRLOCK_TY = 21;
|
||||
|
||||
static bool doorOpen = false;
|
||||
|
||||
static char tileAt(int tx, int ty)
|
||||
{
|
||||
if (tx < 0 || ty < 0 || tx >= nd::TILE_COLS || ty >= nd::TILE_ROWS) return '#';
|
||||
return DEMO_MAP[ty][tx];
|
||||
}
|
||||
|
||||
// blocks unit movement (closed blast door included) — used from M3 on
|
||||
[[maybe_unused]] static bool walkable(int tx, int ty)
|
||||
{
|
||||
char t = tileAt(tx, ty);
|
||||
if (t == '+' && !doorOpen) return false;
|
||||
return t == '.' || t == 'A' || t == 'T' || t == '+';
|
||||
}
|
||||
|
||||
// blocks line-of-sight raycasts — used from M3 on
|
||||
[[maybe_unused]] static bool blocksSight(int tx, int ty)
|
||||
{
|
||||
char t = tileAt(tx, ty);
|
||||
return t == '#' || (t == '+' && !doorOpen);
|
||||
}
|
||||
|
||||
[[maybe_unused]] static int tileIdx(int tx, int ty) { return ty * nd::TILE_COLS + tx; }
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Demo sub-net graph — same coordinate space as the floorplan
|
||||
// (tile coords; door nodes sit exactly on their bulkhead door tiles)
|
||||
// Sub-net (MVP.md §2): 4 nodes in the same coordinate space
|
||||
// ---------------------------------------------------------------------------
|
||||
enum { N_AIRLK, N_JUNC, N_DOOR, N_HIVE };
|
||||
struct NetNode {
|
||||
const char *label;
|
||||
int tx, ty; // tile coords (px center = tile*8+4)
|
||||
int tx, ty;
|
||||
uint16_t color;
|
||||
uint8_t type; // 0 junction, 1 ICE, 2 hive, 3 door controller
|
||||
};
|
||||
enum { NN_AIRLK, NN_SEC, NN_D1, NN_D2, NN_D3, NN_D4, NN_PWR, NN_HIVE };
|
||||
static const NetNode NODES[8] = {
|
||||
{ "AIRLK", 2, 21, nd::C_AIRLOCK, 0 },
|
||||
{ "SEC", 6, 6, nd::C_ICE, 1 },
|
||||
{ "DOOR1", 12, 4, nd::C_DOOR, 3 },
|
||||
{ "DOOR2", 12, 18, nd::C_DOOR, 3 },
|
||||
{ "DOOR3", 19, 8, nd::C_DOOR, 3 },
|
||||
{ "DOOR4", 26, 11, nd::C_DOOR, 3 },
|
||||
{ "PWR", 19, 14, nd::C_NODE, 0 },
|
||||
{ "HIVE", 33, 5, nd::C_HIVE, 2 },
|
||||
static const NetNode NODES[4] = {
|
||||
{ "AIRLK", 4, 20, nd::C_AIRLOCK },
|
||||
{ "JUNC", 18, 6, nd::C_NODE },
|
||||
{ "DOOR", 28, 12, nd::C_DOOR },
|
||||
{ "HIVE", 35, 4, nd::C_HIVE },
|
||||
};
|
||||
static const uint8_t LINKS[7][2] = {
|
||||
{ NN_AIRLK, NN_D2 }, { NN_D2, NN_PWR }, { NN_PWR, NN_D4 },
|
||||
{ NN_D4, NN_HIVE }, { NN_PWR, NN_D3 }, { NN_D3, NN_D1 }, { NN_D1, NN_SEC },
|
||||
static const uint8_t EDGES[3][2] = {
|
||||
{ N_AIRLK, N_JUNC }, { N_JUNC, N_DOOR }, { N_JUNC, N_HIVE },
|
||||
};
|
||||
// packet flow path AIRLK -> DOOR2 -> PWR -> DOOR4 -> HIVE
|
||||
static const uint8_t PACKET_PATH[5] = { NN_AIRLK, NN_D2, NN_PWR, NN_D4, NN_HIVE };
|
||||
static const char *EDGE_LABELS[3] = { "AIRLK-JUNC", "JUNC-DOOR", "JUNC-HIVE" };
|
||||
|
||||
static int nodePx(int i) { return NODES[i].tx * nd::TILE + nd::TILE / 2; }
|
||||
static int nodePy(int i) { return NODES[i].ty * nd::TILE + nd::TILE / 2; }
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Cursor (shared space; snaps to tiles in Cameras, nodes targeted in Network)
|
||||
// ---------------------------------------------------------------------------
|
||||
static int curX = 60, curY = 120;
|
||||
// link build durations (sim ticks @ 50 ms): 1.5 s plain, 3.0 s through ICE
|
||||
static const int LINK_TICKS = 30;
|
||||
static const int ICE_TICKS = 60;
|
||||
// red trace: 4 s from HIVE back to AIRLK
|
||||
static const int TRACE_TICKS = 80;
|
||||
// overheat lockout after a feedback spike
|
||||
static const int HEAT_TICKS = 60;
|
||||
|
||||
// Squad priority beacon (tile coords), starts at the airlock
|
||||
struct NetLink {
|
||||
bool active;
|
||||
uint8_t a, b; // node ids
|
||||
int prog; // build progress in ticks (prog == dur -> ACTIVE)
|
||||
int dur;
|
||||
};
|
||||
static NetLink links[3];
|
||||
|
||||
static bool nodeOnline[4]; // compromised & reachable from AIRLK
|
||||
static bool hiveCracked = false;
|
||||
|
||||
// red trace pulse HIVE -> JUNC -> AIRLK
|
||||
static bool traceActive = false;
|
||||
static int traceProg = 0; // 0..TRACE_TICKS
|
||||
|
||||
// deck thermal: >0 = OVERHEAT lockout (ticks remaining, shown as %)
|
||||
static int heatT = 0;
|
||||
|
||||
// cursor
|
||||
static int curX = 60, curY = 120;
|
||||
static int beaconTX = AIRLOCK_TX, beaconTY = AIRLOCK_TY;
|
||||
|
||||
// transient UI feedback
|
||||
static uint32_t viewFlashUntil = 0; // frame flash after view switch
|
||||
static uint32_t slotFlash = 0xFF; // daemon slot flash id + expiry pair
|
||||
static uint32_t slotFlashUntil = 0;
|
||||
static int nodeFlash = -1; // clicked net node highlight
|
||||
static uint32_t nodeFlashUntil = 0;
|
||||
static uint32_t viewFlashUntil = 0;
|
||||
static char msgText[24] = "";
|
||||
static uint32_t msgUntil = 0;
|
||||
|
||||
static void flashMsg(const char *t)
|
||||
{
|
||||
snprintf(msgText, sizeof(msgText), "%s", t);
|
||||
msgUntil = millis() + 1200;
|
||||
Serial.printf("[msg] %s\n", t);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Trackball input — edge-counting ISRs + momentum model
|
||||
// Quadrant pins + center click, per UnitTest's mouse mapping:
|
||||
// G02 -> right, G01 -> up, G04 -> left, G03 -> down, BOOT -> click
|
||||
// Sub-net logic
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// reachability from AIRLK over ACTIVE links (links form a tree)
|
||||
static void refreshOnline()
|
||||
{
|
||||
bool reach[4] = { true, false, false, false };
|
||||
bool changed = true;
|
||||
while (changed) {
|
||||
changed = false;
|
||||
for (auto &l : links) {
|
||||
if (!l.active || l.prog != l.dur) continue;
|
||||
if (reach[l.a] != reach[l.b]) {
|
||||
reach[l.a] = reach[l.b] = true;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 4; i++) nodeOnline[i] = reach[i];
|
||||
if (!nodeOnline[N_HIVE]) hiveCracked = false;
|
||||
}
|
||||
|
||||
// is there an edge between two nodes?
|
||||
static int edgeBetween(int a, int b)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
if ((EDGES[i][0] == a && EDGES[i][1] == b) ||
|
||||
(EDGES[i][0] == b && EDGES[i][1] == a)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// is a link already routed on this edge (building or active)?
|
||||
static int linkOnEdge(int edge)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
if (links[i].active && edge == i) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void dropLinks()
|
||||
{
|
||||
for (auto &l : links) l.active = false;
|
||||
traceActive = false;
|
||||
refreshOnline();
|
||||
}
|
||||
|
||||
static void tryLink(int node)
|
||||
{
|
||||
if (heatT > 0) { flashMsg("OVERHEAT"); return; }
|
||||
if (nodeOnline[node]) {
|
||||
if (node == N_DOOR) {
|
||||
doorOpen = !doorOpen;
|
||||
Serial.printf("[net] DOOR_CTRL: blast door %s\n", doorOpen ? "OPEN" : "CLOSED");
|
||||
flashMsg(doorOpen ? "DOOR OPEN" : "DOOR CLOSED");
|
||||
return;
|
||||
}
|
||||
flashMsg("ONLINE");
|
||||
return;
|
||||
}
|
||||
// route a link from any online node adjacent to this one
|
||||
int edge = -1, from = -1;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int a = EDGES[i][0], b = EDGES[i][1];
|
||||
if ((a == node && nodeOnline[b]) || (b == node && nodeOnline[a])) {
|
||||
edge = i;
|
||||
from = (a == node) ? b : a;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (edge < 0) { flashMsg("NO UPLINK"); return; }
|
||||
if (linkOnEdge(edge) >= 0) { flashMsg("LINKING..."); return; }
|
||||
|
||||
bool ice = (node == N_HIVE);
|
||||
for (auto &l : links) {
|
||||
if (!l.active) {
|
||||
l.active = true;
|
||||
l.a = from;
|
||||
l.b = node;
|
||||
l.prog = 0;
|
||||
l.dur = ice ? ICE_TICKS : LINK_TICKS;
|
||||
refreshOnline(); // offline until the build completes
|
||||
Serial.printf("[net] routing %s%s (%.1fs)\n", EDGE_LABELS[edge],
|
||||
ice ? " [ICE]" : "", l.dur * nd::SIM_TICK_MS / 1000.0f);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sever the link (and everything that loses its path to AIRLK)
|
||||
static void severLink(int li)
|
||||
{
|
||||
Serial.printf("[net] severed %s\n", EDGE_LABELS[edgeBetween(links[li].a, links[li].b)]);
|
||||
links[li].active = false;
|
||||
refreshOnline();
|
||||
if (!nodeOnline[N_HIVE]) traceActive = false; // trace cut short: reset safely
|
||||
flashMsg("LINK SEVERED");
|
||||
}
|
||||
|
||||
// distance cursor->link segment; returns the hovered link or -1
|
||||
static int hoverLink()
|
||||
{
|
||||
int best = -1;
|
||||
float bestD = 7.0f;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!links[i].active) continue;
|
||||
float x0 = nodePx(links[i].a), y0 = nodePy(links[i].a);
|
||||
float x1 = nodePx(links[i].b), y1 = nodePy(links[i].b);
|
||||
float dx = x1 - x0, dy = y1 - y0;
|
||||
float len2 = dx * dx + dy * dy;
|
||||
float t = ((curX - x0) * dx + (curY - y0) * dy) / len2;
|
||||
if (t < 0) t = 0;
|
||||
if (t > 1) t = 1;
|
||||
float px = x0 + t * dx, py = y0 + t * dy;
|
||||
float d = hypotf(curX - px, curY - py);
|
||||
if (d < bestD) { bestD = d; best = i; }
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
static void spawnTrace()
|
||||
{
|
||||
traceActive = true;
|
||||
traceProg = 0;
|
||||
Serial.println("[net] TRACE detected: red pulse inbound!");
|
||||
}
|
||||
|
||||
static void feedbackSpike()
|
||||
{
|
||||
traceActive = false;
|
||||
dropLinks();
|
||||
heatT = HEAT_TICKS;
|
||||
Serial.println("[net] FEEDBACK SPIKE: links dropped, OVERHEAT 3s, reinforcement inbound");
|
||||
flashMsg("FEEDBACK!");
|
||||
// reinforcement droid spawns in M3
|
||||
}
|
||||
|
||||
static void stepNetwork()
|
||||
{
|
||||
// link builds
|
||||
for (auto &l : links) {
|
||||
if (!l.active || l.prog == l.dur) continue;
|
||||
l.prog++;
|
||||
if (l.prog == l.dur) {
|
||||
refreshOnline();
|
||||
if (l.b == N_HIVE && nodeOnline[N_HIVE]) {
|
||||
hiveCracked = true;
|
||||
spawnTrace();
|
||||
} else {
|
||||
Serial.printf("[net] link up: %s\n", EDGE_LABELS[edgeBetween(l.a, l.b)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// red trace
|
||||
if (traceActive) {
|
||||
traceProg++;
|
||||
if (traceProg >= TRACE_TICKS) feedbackSpike();
|
||||
}
|
||||
// thermal cooldown
|
||||
if (heatT > 0) {
|
||||
heatT--;
|
||||
if (heatT == 0) Serial.println("[net] deck cooled: systems online");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Scenario reset (MVP: R replays the 60-second scenario instantly)
|
||||
// ---------------------------------------------------------------------------
|
||||
static void resetScenario()
|
||||
{
|
||||
for (auto &l : links) l.active = false;
|
||||
traceActive = false;
|
||||
traceProg = 0;
|
||||
hiveCracked = false;
|
||||
heatT = 0;
|
||||
doorOpen = false;
|
||||
refreshOnline(); // AIRLK root comes up online
|
||||
paused = true;
|
||||
// entities (marines/droids) arrive in M3
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Trackball input — edge-counting ISRs + momentum (unchanged from M1)
|
||||
// ---------------------------------------------------------------------------
|
||||
static volatile uint32_t tbEdges[4];
|
||||
static volatile uint32_t tbClicks;
|
||||
@@ -180,18 +399,18 @@ static void IRAM_ATTR tbIsrLeft() { tbEdges[2]++; }
|
||||
static void IRAM_ATTR tbIsrDown() { tbEdges[3]++; }
|
||||
static void IRAM_ATTR tbIsrClick() { tbClicks++; }
|
||||
|
||||
static const int TB_FP = 8; // velocity fixed point
|
||||
static const int TB_FP = 8;
|
||||
#ifdef EMULATOR
|
||||
static const int TB_IMPULSE = 6; // emulated: rich edge rate
|
||||
static const int TB_FRICTION = 12; // velocity kept per frame (of 16)
|
||||
static const int TB_IMPULSE = 6;
|
||||
static const int TB_FRICTION = 12;
|
||||
#else
|
||||
static const int TB_IMPULSE = 24; // device: fewer edges to move
|
||||
static const int TB_IMPULSE = 24;
|
||||
static const int TB_FRICTION = 15;
|
||||
#endif
|
||||
static const int TB_VMAX = 24 << TB_FP; // hard-flick cap
|
||||
static const int TB_VMAX = 24 << TB_FP;
|
||||
|
||||
static int32_t tbVelX, tbVelY; // momentum, 1/8 px per frame
|
||||
static int32_t tbRemX, tbRemY; // sub-pixel accumulators
|
||||
static int32_t tbVelX, tbVelY;
|
||||
static int32_t tbRemX, tbRemY;
|
||||
|
||||
static void attachTrackball()
|
||||
{
|
||||
@@ -223,25 +442,14 @@ static void clampCursor()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// View mode
|
||||
// ---------------------------------------------------------------------------
|
||||
static void toggleView()
|
||||
{
|
||||
viewMode = (viewMode == VM_CAMERAS) ? VM_NETWORK : VM_CAMERAS;
|
||||
viewFlashUntil = millis() + 350;
|
||||
Serial.printf("[key] view -> %s\n",
|
||||
viewMode == VM_CAMERAS ? "CAMERAS" : "NETWORK");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Primary action (groundwork: M3 beacon placement, M2 node routing)
|
||||
// Primary action
|
||||
// ---------------------------------------------------------------------------
|
||||
static void registerClick()
|
||||
{
|
||||
if (viewMode == VM_CAMERAS) {
|
||||
int tx = curX / nd::TILE, ty = curY / nd::TILE;
|
||||
char t = DEMO_MAP[ty][tx];
|
||||
if (t != '#') { // beacons can't sit inside walls
|
||||
char t = tileAt(tx, ty);
|
||||
if (t != '#') {
|
||||
beaconTX = tx;
|
||||
beaconTY = ty;
|
||||
Serial.printf("[click] beacon -> tile %d,%d\n", tx, ty);
|
||||
@@ -249,17 +457,16 @@ static void registerClick()
|
||||
Serial.println("[click] wall tile: beacon ignored");
|
||||
}
|
||||
} else {
|
||||
// nearest demo node flash (routing groundwork for Milestone 2)
|
||||
// nearest node
|
||||
int best = -1, bestD = 1 << 30;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int dx = curX - nodePx(i);
|
||||
int dy = curY - nodePy(i);
|
||||
int d = dx * dx + dy * dy;
|
||||
if (d < bestD) { bestD = d; best = i; }
|
||||
}
|
||||
nodeFlash = best;
|
||||
nodeFlashUntil = millis() + 400;
|
||||
Serial.printf("[click] node %s targeted\n", NODES[best].label);
|
||||
if (bestD > 24 * 24) { flashMsg("NO NODE"); return; }
|
||||
tryLink(best);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,24 +480,33 @@ static void handleKey(char c)
|
||||
paused = !paused;
|
||||
Serial.printf("[key] tactical freeze %s\n", paused ? "ON" : "OFF");
|
||||
break;
|
||||
case 'p': case '\t': // '\t' kept as legacy alias for the pane era
|
||||
toggleView();
|
||||
case 'p': case '\t':
|
||||
viewMode = (viewMode == VM_CAMERAS) ? VM_NETWORK : VM_CAMERAS;
|
||||
viewFlashUntil = millis() + 350;
|
||||
Serial.printf("[key] view -> %s\n",
|
||||
viewMode == VM_CAMERAS ? "CAMERAS" : "NETWORK");
|
||||
break;
|
||||
case '1': case '2': case '3': case '4':
|
||||
slotFlash = c - '1';
|
||||
slotFlashUntil = millis() + 400;
|
||||
Serial.printf("[key] arm daemon slot %d (M4 groundwork)\n", c - '1');
|
||||
case '1': case '2':
|
||||
if (heatT > 0) { flashMsg("OVERHEAT"); break; }
|
||||
if (!nodeOnline[N_HIVE]) { flashMsg("NO HIVE LINK"); break; }
|
||||
// FRENZY / BLIND payloads land in Milestone 4
|
||||
Serial.printf("[key] daemon %c armed (effect lands in M4)\n", c);
|
||||
flashMsg("M4 PENDING");
|
||||
break;
|
||||
case 'x':
|
||||
Serial.println("[key] kill-switch sever (M2 groundwork)");
|
||||
case 'x': {
|
||||
if (heatT > 0) { flashMsg("OVERHEAT"); break; }
|
||||
int li = hoverLink();
|
||||
if (li >= 0) severLink(li);
|
||||
else flashMsg("NO LINK HERE");
|
||||
break;
|
||||
}
|
||||
case 'r':
|
||||
Serial.println("[key] tactical retreat (M3 groundwork)");
|
||||
beaconTX = AIRLOCK_TX;
|
||||
beaconTY = AIRLOCK_TY;
|
||||
Serial.println("[key] RESET");
|
||||
resetScenario();
|
||||
Serial.println("[reset] scenario re-armed (paused)");
|
||||
break;
|
||||
case 'q': case 'e':
|
||||
Serial.printf("[key] cycle %s (M2 groundwork)\n", c == 'q' ? "back" : "fwd");
|
||||
Serial.printf("[key] cycle %s (groundwork)\n", c == 'q' ? "back" : "fwd");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -302,7 +518,7 @@ static void pollKeyboard()
|
||||
static char lastKey = 0;
|
||||
Wire.requestFrom((uint8_t)0x55, (uint8_t)1);
|
||||
if (Wire.available() == 0) {
|
||||
lastKey = 0; // idle: arm the next press (same key can repeat)
|
||||
lastKey = 0;
|
||||
return;
|
||||
}
|
||||
char k = (char)Wire.read();
|
||||
@@ -323,7 +539,8 @@ static void pollTouch()
|
||||
if (!down) { wasDown = false; return; }
|
||||
if (wasDown) return; // only act on new taps
|
||||
int16_t x[1], y[1];
|
||||
if (touch.getPoint(x, y, 1) > 0) {
|
||||
int gp = touch.getPoint(x, y, 1);
|
||||
if (gp > 0) {
|
||||
wasDown = true;
|
||||
curX = x[0];
|
||||
curY = y[0];
|
||||
@@ -333,8 +550,7 @@ static void pollTouch()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Trackball -> cursor (momentum, capped; cursor stays live during the freeze
|
||||
// because planning happens while paused)
|
||||
// Trackball -> cursor
|
||||
// ---------------------------------------------------------------------------
|
||||
static void applyTrackball()
|
||||
{
|
||||
@@ -368,18 +584,18 @@ static void applyTrackball()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Simulation — deterministic 20 Hz ticks (grows into M2/M3 systems)
|
||||
// Simulation — deterministic 20 Hz ticks
|
||||
// ---------------------------------------------------------------------------
|
||||
static void stepSim()
|
||||
{
|
||||
simTick++;
|
||||
stepNetwork();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Rendering
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// palette color of a map tile
|
||||
static uint16_t tileColor(char t)
|
||||
{
|
||||
switch (t) {
|
||||
@@ -387,11 +603,11 @@ static uint16_t tileColor(char t)
|
||||
case 'o': return nd::C_COVER;
|
||||
case '+': return nd::C_DOOR;
|
||||
case 'A': return nd::C_AIRLOCK;
|
||||
case 'T': return nd::C_NODE;
|
||||
default: return nd::C_FLOOR;
|
||||
}
|
||||
}
|
||||
|
||||
// ~35% brightness ghost of an RGB565 color (Network mode dims the ship view)
|
||||
static uint16_t dim565(uint16_t c)
|
||||
{
|
||||
uint32_t r = (((c >> 11) & 0x1F) * 22) >> 6;
|
||||
@@ -405,27 +621,76 @@ static void renderMap(bool dim)
|
||||
for (int ty = 0; ty < nd::TILE_ROWS; ty++) {
|
||||
const char *row = DEMO_MAP[ty];
|
||||
for (int tx = 0; tx < nd::TILE_COLS; tx++) {
|
||||
uint16_t c = tileColor(row[tx]);
|
||||
char t = row[tx];
|
||||
uint16_t c = tileColor(t);
|
||||
if (dim) c = dim565(c);
|
||||
// the blast door: amber block when closed, open frame when open
|
||||
if (t == '+' && doorOpen) c = dim ? dim565(nd::C_FLOOR) : nd::C_FLOOR;
|
||||
GFXP->fillRect(tx * nd::TILE, ty * nd::TILE, nd::TILE, nd::TILE, c);
|
||||
if (row[tx] == 'A') { // airlock outline pops on the floor
|
||||
if (t == '+' && doorOpen) {
|
||||
uint16_t dc = dim ? dim565(nd::C_DOOR) : nd::C_DOOR;
|
||||
GFXP->fillRect(tx * nd::TILE, ty * nd::TILE, 2, nd::TILE, dc);
|
||||
GFXP->fillRect(tx * nd::TILE + 6, ty * nd::TILE, 2, nd::TILE, dc);
|
||||
}
|
||||
if (t == 'A') {
|
||||
GFXP->drawRect(tx * nd::TILE, ty * nd::TILE, nd::TILE, nd::TILE,
|
||||
dim ? dim565(nd::C_FLOOR) : nd::C_FLOOR);
|
||||
}
|
||||
if (t == 'T') { // objective terminal: dark rack + cyan screen
|
||||
uint16_t dc = dim ? dim565(nd::C_HUDBG) : nd::C_HUDBG;
|
||||
GFXP->fillRect(tx * nd::TILE, ty * nd::TILE, nd::TILE, nd::TILE, dc);
|
||||
GFXP->fillRect(tx * nd::TILE + 1, ty * nd::TILE + 1, 6, 3,
|
||||
dim ? dim565(nd::C_PACKET) : nd::C_PACKET);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// partial line: solid fraction, dotted remainder (link build animation)
|
||||
static void drawLinkLine(int x0, int y0, int x1, int y1, float frac,
|
||||
uint16_t solid, uint16_t dotted, bool dottedFirst)
|
||||
{
|
||||
int dx = abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
|
||||
int dy = -abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
|
||||
int err = dx + dy;
|
||||
int steps = dx - dy; // bresenham step count approx
|
||||
int solidSteps = (int)(steps * frac);
|
||||
int i = 0;
|
||||
for (;;) {
|
||||
bool solidPix = dottedFirst ? (i >= steps - solidSteps)
|
||||
: (i < solidSteps);
|
||||
if (solidPix) GFXP->drawPixel(x0, y0, solid);
|
||||
else if ((i & 1) == 0) GFXP->drawPixel(x0, y0, dotted);
|
||||
if (x0 == x1 && y0 == y1) break;
|
||||
int e2 = 2 * err;
|
||||
if (e2 >= dy) { err += dy; x0 += sx; }
|
||||
if (e2 <= dx) { err += dx; y0 += sy; }
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
static void renderNetwork(bool full)
|
||||
{
|
||||
// links: solid trace (Network) vs dotted ghost outline (Cameras)
|
||||
for (auto &l : LINKS) {
|
||||
int x0 = nodePx(l[0]), y0 = nodePy(l[0]);
|
||||
int x1 = nodePx(l[1]), y1 = nodePy(l[1]);
|
||||
if (full) {
|
||||
GFXP->drawLine(x0, y0, x1, y1, nd::C_LINK);
|
||||
// links: active solid, building partial, ghost outlines in cameras mode
|
||||
for (int i = 0; i < 3; i++) {
|
||||
auto &l = links[i];
|
||||
int x0 = nodePx(l.a), y0 = nodePy(l.a);
|
||||
int x1 = nodePx(l.b), y1 = nodePy(l.b);
|
||||
bool hovered = (hoverLink() == i && full);
|
||||
uint16_t solidC = hovered ? nd::C_CURSOR : nd::C_LINK;
|
||||
if (l.active && full) {
|
||||
if (l.prog < l.dur) {
|
||||
drawLinkLine(x0, y0, x1, y1, (float)l.prog / l.dur,
|
||||
solidC, nd::C_PACKET, false);
|
||||
} else {
|
||||
// dotted line: every other pixel of a Bresenham walk
|
||||
GFXP->drawLine(x0, y0, x1, y1, solidC);
|
||||
}
|
||||
} else if (l.active && !full) {
|
||||
if (l.prog < l.dur) {
|
||||
drawLinkLine(x0, y0, x1, y1, (float)l.prog / l.dur,
|
||||
nd::C_GHOST, nd::C_GHOST, false);
|
||||
} else {
|
||||
for (int k = 0; k <= 1; k++) {} // dotted ghost:
|
||||
int dx = abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
|
||||
int dy = -abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
|
||||
int err = dx + dy, step = 0;
|
||||
@@ -438,29 +703,55 @@ static void renderNetwork(bool full)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// data packets flowing along the packet path (freeze with the sim)
|
||||
int segs = 4, per = 36;
|
||||
int tt = (int)(simTick % (uint32_t)(segs * per));
|
||||
int seg = tt / per, f = tt % per;
|
||||
int a = PACKET_PATH[seg], b = PACKET_PATH[seg + 1];
|
||||
int px = nodePx(a) + (nodePx(b) - nodePx(a)) * f / per;
|
||||
int py = nodePy(a) + (nodePy(b) - nodePy(a)) * f / per;
|
||||
GFXP->fillCircle(px, py, full ? 2 : 1, nd::C_PACKET);
|
||||
if (full) GFXP->drawPixel(px, py, TFT_WHITE);
|
||||
// red trace pulse along HIVE -> JUNC -> AIRLK
|
||||
if (traceActive) {
|
||||
float f = (float)traceProg / TRACE_TICKS * 2.0f; // 2 segments
|
||||
int seg = (f >= 1.0f) ? 1 : 0;
|
||||
float t = f - seg;
|
||||
int x0 = nodePx(N_HIVE), y0 = nodePy(N_HIVE);
|
||||
int x1 = nodePx(N_JUNC), y1 = nodePy(N_JUNC);
|
||||
if (seg == 1) { x0 = nodePx(N_JUNC); y0 = nodePy(N_JUNC); x1 = nodePx(N_AIRLK); y1 = nodePy(N_AIRLK); }
|
||||
int px = x0 + (int)((x1 - x0) * t);
|
||||
int py = y0 + (int)((y1 - y0) * t);
|
||||
GFXP->fillCircle(px, py, 3, nd::C_TRACE);
|
||||
GFXP->drawCircle(px, py, 5, nd::C_TRACE);
|
||||
}
|
||||
|
||||
// nodes: filled icons + labels (Network) vs hollow outlines (Cameras)
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// nodes
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int nx = nodePx(i), ny = nodePy(i);
|
||||
bool flashing = (nodeFlash == i && (int32_t)(millis() - nodeFlashUntil) < 0);
|
||||
int hoverDx = curX - nx, hoverDy = curY - ny;
|
||||
bool hovered = viewMode == VM_NETWORK && hoverDx * hoverDx + hoverDy * hoverDy < 24 * 24;
|
||||
if (full) {
|
||||
GFXP->fillCircle(nx, ny, 6, flashing ? nd::C_CURSOR : NODES[i].color);
|
||||
if (nodeOnline[i]) {
|
||||
GFXP->fillCircle(nx, ny, 6, NODES[i].color);
|
||||
GFXP->drawCircle(nx, ny, 6, TFT_BLACK);
|
||||
GFXP->setTextDatum(TC_DATUM);
|
||||
GFXP->setTextColor(nd::C_TEXTDIM);
|
||||
GFXP->drawString(NODES[i].label, nx, ny + 9);
|
||||
} else {
|
||||
GFXP->drawCircle(nx, ny, 6, flashing ? nd::C_CURSOR : nd::C_GHOST);
|
||||
GFXP->drawCircle(nx, ny, 6, hovered ? nd::C_CURSOR : nd::C_GHOST);
|
||||
}
|
||||
GFXP->setTextDatum(TC_DATUM);
|
||||
GFXP->setTextColor(nodeOnline[i] ? nd::C_TEXT : nd::C_TEXTDIM);
|
||||
GFXP->drawString(NODES[i].label, nx, ny + 9);
|
||||
// door state on the door node
|
||||
if (i == N_DOOR && nodeOnline[i]) {
|
||||
GFXP->setTextColor(doorOpen ? nd::C_GOOD : nd::C_TRACE);
|
||||
GFXP->drawString(doorOpen ? "OPEN" : "SHUT", nx, ny + 19);
|
||||
}
|
||||
// ICE crack progress on the hive
|
||||
if (i == N_HIVE) {
|
||||
for (int k = 0; k < 3; k++) {
|
||||
if (links[k].active && links[k].b == N_HIVE && links[k].prog < links[k].dur) {
|
||||
GFXP->setTextColor(nd::C_TRACE);
|
||||
GFXP->drawString("CRACKING", nx, ny + 19);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
GFXP->drawCircle(nx, ny, 6,
|
||||
nodeOnline[i] ? nd::C_GHOST
|
||||
: (hovered ? nd::C_CURSOR : nd::C_GHOST));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,7 +764,6 @@ static void renderNetwork(bool full)
|
||||
|
||||
static void renderBeacon()
|
||||
{
|
||||
// squad priority beacon (cyan diamond at the beacon tile center)
|
||||
int bx = beaconTX * nd::TILE + nd::TILE / 2;
|
||||
int by = beaconTY * nd::TILE + nd::TILE / 2;
|
||||
uint16_t c = (viewMode == VM_NETWORK) ? dim565(nd::C_BEACON) : nd::C_BEACON;
|
||||
@@ -493,27 +783,24 @@ static void renderHud()
|
||||
GFXP->fillRect(nd::HUD_X, nd::HUD_Y, nd::HUD_W, nd::HUD_H, nd::C_HUDBG);
|
||||
GFXP->drawFastHLine(nd::HUD_X, nd::HUD_Y, nd::HUD_W, nd::C_BORDER);
|
||||
|
||||
// 4 exploit daemon slots: keycap, name, cooldown bar
|
||||
static const char *const NAMES[4] = { "FRENZY", "BLIND", "OVRCLK", "PATCH" };
|
||||
static const int COOL[4] = { 30, 55, 80, 45 };
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// 2 exploit daemon slots (MVP: FRENZY + BLIND)
|
||||
static const char *const NAMES[2] = { "FRENZY", "BLIND" };
|
||||
for (int i = 0; i < 2; i++) {
|
||||
int x = 6 + i * 58, y = nd::HUD_Y + 6;
|
||||
bool flashing = (slotFlash == (uint32_t)i && (int32_t)(millis() - slotFlashUntil) < 0);
|
||||
uint16_t tc = flashing ? nd::C_CURSOR : nd::C_TEXT;
|
||||
GFXP->setTextColor(tc);
|
||||
GFXP->setTextDatum(TL_DATUM);
|
||||
GFXP->setTextColor(nd::C_TEXT);
|
||||
GFXP->drawString(String("[") + char('1' + i) + "]", x, y);
|
||||
GFXP->setTextColor(nd::C_TEXTDIM);
|
||||
GFXP->drawString(NAMES[i], x + 18, y);
|
||||
meterBar(x, y + 14, 48, 6, COOL[i], nd::C_GOOD);
|
||||
meterBar(x, y + 14, 48, 6, 100, nodeOnline[N_HIVE] ? nd::C_GOOD : nd::C_BORDER);
|
||||
}
|
||||
|
||||
// RAM + thermal load
|
||||
GFXP->setTextColor(nd::C_TEXT);
|
||||
GFXP->drawString("RAM 4/6", 246, nd::HUD_Y + 6);
|
||||
meterBar(246, nd::HUD_Y + 16, 56, 7, 42, nd::C_WARN);
|
||||
GFXP->setTextColor(nd::C_TEXTDIM);
|
||||
GFXP->drawString("TEMP", 246, nd::HUD_Y + 25);
|
||||
// TEMP bar (overheat lockout)
|
||||
int heatPct = heatT * 100 / HEAT_TICKS;
|
||||
GFXP->setTextColor(heatT > 0 ? nd::C_HOT : nd::C_TEXT);
|
||||
GFXP->drawString(heatT > 0 ? "OVERHEAT" : "TEMP", 130, nd::HUD_Y + 6);
|
||||
meterBar(130, nd::HUD_Y + 16, 56, 7, heatT > 0 ? heatPct : 15,
|
||||
heatT > 0 ? nd::C_HOT : nd::C_WARN);
|
||||
|
||||
// pause hint / state
|
||||
GFXP->setTextDatum(TR_DATUM);
|
||||
@@ -521,35 +808,40 @@ static void renderHud()
|
||||
GFXP->drawString("SPACE", nd::HUD_X + nd::HUD_W - 6, nd::HUD_Y + 6);
|
||||
GFXP->setTextColor(paused ? nd::C_FREEZE : nd::C_TEXTDIM);
|
||||
GFXP->drawString(paused ? "RESUME" : "PAUSE", nd::HUD_X + nd::HUD_W - 6, nd::HUD_Y + 16);
|
||||
GFXP->setTextColor(nd::C_TEXTDIM);
|
||||
GFXP->drawString("R: RESET", nd::HUD_X + nd::HUD_W - 6, nd::HUD_Y + 32);
|
||||
GFXP->setTextDatum(TL_DATUM);
|
||||
|
||||
// view mode indicator
|
||||
GFXP->setTextColor(nd::C_FREEZE);
|
||||
GFXP->setTextDatum(TR_DATUM);
|
||||
GFXP->setTextColor(nd::C_FREEZE);
|
||||
GFXP->drawString(viewMode == VM_CAMERAS ? "VIEW: CAMERAS [P]" : "VIEW: NETWORK [P]",
|
||||
nd::HUD_X + nd::HUD_W - 6, nd::HUD_Y + 32);
|
||||
nd::HUD_X + 190, nd::HUD_Y + 32);
|
||||
GFXP->setTextDatum(TL_DATUM);
|
||||
|
||||
// squad health pips
|
||||
// squad readout (live marine HP in M3; placeholder now)
|
||||
GFXP->setTextColor(nd::C_TEXTDIM);
|
||||
GFXP->drawString("SQUAD", 6, nd::HUD_Y + 30);
|
||||
static const int HP[3] = { 4, 5, 2 }; // of 5 (M3 groundwork)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
int x = 48 + i * 58;
|
||||
for (int s = 0; s < 5; s++) {
|
||||
uint16_t c = s < HP[i] ? nd::C_GOOD : nd::C_BORDER;
|
||||
GFXP->fillRect(x + s * 8, nd::HUD_Y + 34, 6, 8, c);
|
||||
GFXP->fillRect(x + s * 8, nd::HUD_Y + 34, 6, 8, nd::C_GOOD);
|
||||
}
|
||||
GFXP->setTextColor(nd::C_TEXTDIM);
|
||||
GFXP->drawString(String("M") + String(i + 1), x - 10, nd::HUD_Y + 30);
|
||||
}
|
||||
|
||||
// transient message
|
||||
if ((int32_t)(millis() - msgUntil) < 0) {
|
||||
GFXP->setTextColor(nd::C_CURSOR);
|
||||
GFXP->drawString(msgText, 200, nd::HUD_Y + 6);
|
||||
}
|
||||
}
|
||||
|
||||
static void renderCursor()
|
||||
{
|
||||
uint16_t c = (viewMode == VM_NETWORK) ? nd::C_PACKET : nd::C_CURSOR;
|
||||
if (viewMode == VM_CAMERAS) {
|
||||
// tile snap highlight + crosshair
|
||||
int tx = curX / nd::TILE, ty = curY / nd::TILE;
|
||||
GFXP->drawRect(tx * nd::TILE, ty * nd::TILE, nd::TILE, nd::TILE, c);
|
||||
GFXP->drawCircle(curX, curY, 3, c);
|
||||
@@ -560,7 +852,6 @@ static void renderCursor()
|
||||
}
|
||||
}
|
||||
|
||||
// CRT freeze tint: scanlines over the view + status text (DESIGN.md §4)
|
||||
static void renderFreezeTint()
|
||||
{
|
||||
for (int y = 0; y < nd::VIEW_H; y += 3) {
|
||||
@@ -581,7 +872,6 @@ static void render()
|
||||
renderBeacon();
|
||||
renderHud();
|
||||
|
||||
// HUD separator (flashes when the view mode switches)
|
||||
uint16_t bc = (int32_t)(millis() - viewFlashUntil) < 0 ? nd::C_CURSOR : nd::C_BORDER;
|
||||
GFXP->drawFastHLine(nd::HUD_X, nd::HUD_Y - 1, nd::HUD_W, bc);
|
||||
if ((int32_t)(millis() - viewFlashUntil) < 0) {
|
||||
@@ -592,9 +882,6 @@ static void render()
|
||||
if (paused) renderFreezeTint();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Boot screen
|
||||
// ---------------------------------------------------------------------------
|
||||
static void drawBoot()
|
||||
{
|
||||
GFXP->fillScreen(TFT_BLACK);
|
||||
@@ -606,9 +893,9 @@ static void drawBoot()
|
||||
GFXP->drawString("BREACH & BOARD", 160, 108);
|
||||
GFXP->setTextFont(2);
|
||||
GFXP->setTextColor(nd::C_TEXTDIM);
|
||||
GFXP->drawString("M1 // SANDBOX", 160, 136);
|
||||
GFXP->drawString("M2 // VERTICAL SLICE", 160, 136);
|
||||
GFXP->drawString("p: cameras/network space: freeze", 160, 158);
|
||||
GFXP->drawString("ball: cursor enter: select", 160, 174);
|
||||
GFXP->drawString("ball: cursor enter: select x: sever", 160, 174);
|
||||
GFXP->setTextDatum(TL_DATUM);
|
||||
GFXP->setTextFont(1);
|
||||
}
|
||||
@@ -619,12 +906,11 @@ static void drawBoot()
|
||||
static void hardwareInit()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("NetDeck M1 — hardware sandbox");
|
||||
Serial.println("NetDeck M2 — vertical slice (network & traces)");
|
||||
|
||||
pinMode(BOARD_POWERON, OUTPUT); // power rail first (battery boot)
|
||||
pinMode(BOARD_POWERON, OUTPUT);
|
||||
digitalWrite(BOARD_POWERON, HIGH);
|
||||
|
||||
// CS lines high during init
|
||||
pinMode(BOARD_SDCARD_CS, OUTPUT);
|
||||
pinMode(RADIO_CS_PIN, OUTPUT);
|
||||
pinMode(BOARD_TFT_CS, OUTPUT);
|
||||
@@ -661,13 +947,13 @@ void setup()
|
||||
hardwareInit();
|
||||
|
||||
#ifndef EMULATOR
|
||||
// second buffer for flicker-free full-frame pushes
|
||||
fb.setColorDepth(16);
|
||||
if (!fb.createSprite(tft.width(), tft.height()))
|
||||
Serial.println("NetDeck: framebuffer alloc failed (blank screen)");
|
||||
#endif
|
||||
|
||||
drawBoot();
|
||||
resetScenario();
|
||||
stateT0 = millis();
|
||||
lastFrameMs = stateT0;
|
||||
}
|
||||
@@ -680,31 +966,28 @@ void loop()
|
||||
if (now - stateT0 >= nd::BOOT_MS) {
|
||||
gameState = ST_RUN;
|
||||
stateT0 = now;
|
||||
// swallow stale keyboard bytes + trackball edges from floating pins
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (Wire.requestFrom((uint8_t)0x55, (uint8_t)16) == 0) break;
|
||||
}
|
||||
resetTrackball();
|
||||
Serial.println("[boot] entering sandbox (view: cameras)");
|
||||
Serial.println("[boot] encounter loaded (paused, cameras view)");
|
||||
}
|
||||
delay(1);
|
||||
return;
|
||||
}
|
||||
|
||||
// frame pacing ~30 fps
|
||||
static uint32_t nextFrame = 0;
|
||||
if ((int32_t)(now - nextFrame) < 0) { delay(1); return; }
|
||||
nextFrame = now + nd::FRAME_MS;
|
||||
|
||||
uint32_t dt = now - lastFrameMs;
|
||||
lastFrameMs = now;
|
||||
if (dt > 200) dt = 200; // clamp hiccups (debug stalls, USB pauses)
|
||||
if (dt > 200) dt = 200;
|
||||
|
||||
applyTrackball();
|
||||
pollTouch();
|
||||
pollKeyboard();
|
||||
|
||||
// fixed-timestep simulation (DESIGN.md §6)
|
||||
if (!paused) {
|
||||
simAcc += dt;
|
||||
while (simAcc >= nd::SIM_TICK_MS) {
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
To validate the core premise of **NetDeck: Breach & Board**—specifically whether *pausing time to manipulate a network graph while watching an autonomous squad survive a room breach* feels tense, readable, and fun on a 320x240 screen—you only need **one single room-breach encounter**.
|
||||
|
||||
Strip out sector maps, upgrades, multiple classes, oxygen systems, and procedural generation. Build a single, self-contained **Vertical Slice Sandbox** with these exact features:
|
||||
|
||||
---
|
||||
|
||||
### 1. Physical Deck Pane (184x192) — The Combat Arena
|
||||
|
||||
* **One Hardcoded 3-Room Floorplan:**
|
||||
* *Room 1 (Airlock):* Where your squad spawns safely out of enemy line-of-sight.
|
||||
* *Room 2 (Main Corridor):* Contains 2 low-cover crates and 2 patrolling/stationary security droids.
|
||||
* *Room 3 (Server Room):* Guarded by 1 heavy droid + 1 automated ceiling turret, housing the objective terminal.
|
||||
|
||||
|
||||
* **2 Identical Marines (No Classes Yet):**
|
||||
* Represented by simple colored `8x8` or `12x12` sprites with a tiny overhead health bar.
|
||||
* **Pathfinding:** Simple BFS/A* toward a single player-placed **Priority Beacon** (trackball click on any walkable floor tile).
|
||||
* **Combat AI:** If an enemy is within range and line-of-sight (simple Bresenham tile raycast), stop and fire periodic hitscan/tracer lines. Standing adjacent to a cover crate cuts incoming hit chance by 50%.
|
||||
|
||||
|
||||
* **2 Enemy Types:**
|
||||
* *Security Droid:* Basic HP, shoots at marines.
|
||||
* *Ceiling Turret:* Stationary, high rate of fire, shreds marines in seconds unless hacked or bypassed.
|
||||
|
||||
|
||||
* **1 Interactive Blast Door:** Separates Room 2 and Room 3. Can be toggled open/closed via the network pane to trap droids or buy time.
|
||||
|
||||
### 2. Sub-Net Pane (136x192) — The Hacking Graph
|
||||
|
||||
* **4 Hardcoded Nodes:**
|
||||
1. `[AIRLOCK]` (Your starting root node).
|
||||
2. `[JUNCTION]` (Unprotected bridge node).
|
||||
3. `[DOOR_CTRL]` (Connected to Junction — toggles the blast door between Rooms 2 and 3).
|
||||
4. `[HIVE_CORE]` (Connected to Junction — protected by a 3-second ICE lock; controls the droids and turret).
|
||||
|
||||
|
||||
* **Link Routing & Severing:**
|
||||
* Clicking an adjacent node from an already-compromised node starts building a link (animated dotted line turning solid over 1.5s, or 3.0s if ICE-locked).
|
||||
* Pressing **`X`** while hovering over a link immediately severs it.
|
||||
|
||||
|
||||
* **Only 2 Exploit Daemons (Keys `1` and `2`):**
|
||||
* You only need two contrasting verbs to test the tactical loop:
|
||||
1. **`1: FRENZY` (Offensive Chaos):** Requires an active link to `[HIVE_CORE]`. For 5 seconds, droids and the turret target the closest entity (including each other).
|
||||
2. **`2: BLIND` (Tactical Utility):** Requires an active link to `[HIVE_CORE]`. For 6 seconds, droids/turret cannot fire, giving your squad time to cross open floor into cover.
|
||||
|
||||
|
||||
|
||||
|
||||
* **1 Enemy Counter-Measure (The Red Trace):**
|
||||
* As soon as your link to `[HIVE_CORE]` finishes cracking, a red pulse spawns at `[HIVE_CORE]` and travels back toward `[AIRLOCK]` over **4 seconds**.
|
||||
* If it hits `[AIRLOCK]`, your link drops, your deck locks out for 3 seconds ("OVERHEAT"), and a reinforcement droid spawns. Severing the link with `X` before it arrives resets the trace safely.
|
||||
|
||||
|
||||
|
||||
### 3. Minimal HUD & Flow Control (320x48)
|
||||
|
||||
* **`Space` (Tactical Pause):** Freezes the 20 Hz simulation tick instantly and draws a subtle `"PAUSED"` border/tint so you can calmly queue a link or move the squad beacon.
|
||||
* **`Tab` (Pane Snap):** Warps the cursor between the center of the Left Pane and Right Pane so you never waste time scrolling the trackball across the whole screen.
|
||||
* **HUD Readouts:** Just `[1:FRENZY] [2:BLIND]`, a `TEMP` bar (or cooldown timer), and a `RESET (R)` hotkey so you can replay the 60-second scenario instantly after winning or wiping.
|
||||
|
||||
---
|
||||
|
||||
### What to Intentionally Cut from the MVP
|
||||
|
||||
To keep this buildable in a few evenings, ruthlessly exclude:
|
||||
|
||||
* **RAM / Bandwidth math:** Use simple per-daemon cooldown timers instead of a resource pool.
|
||||
* **Procedural map/graph generation:** Hand-tune the single 3-room layout until the timing between squad movement, ICE cracking, and the 4-second red trace feels razor-sharp.
|
||||
* **Sound effects / SD card loading:** Compile your `8x8` sprites and map arrays directly into `const` headers in Flash.
|
||||
* **Menus, title screens, and progression:** Boot straight into the paused encounter; on win/loss, show a 1-line banner (`BREACH SUCCESS` / `SQUAD KIA`) and let `R` reset the state struct.
|
||||
|
||||
### The Litmus Test for This MVP
|
||||
|
||||
Once this slice is running on the T-Deck, play it 5 times in a row. If you find yourself naturally hitting `Space` when the turret opens fire, slamming the blast door shut via `[DOOR_CTRL]`, cracking `[HIVE_CORE]` while your squad hugs cover, triggering `1: FRENZY` to watch the turret wipe out the droids, and hitting `X` right before the red trace reaches your airlock—you know the core game loop works and deserves a full sector generator around it.
|
||||
+33
-1
@@ -8,7 +8,7 @@ milestone lands.
|
||||
| --- | --- | --- |
|
||||
| **M0 — Emulator** | SDL2 emulator support + M1 surface tested locally | **done** |
|
||||
| **M1 — Hardware Sandbox** | Full-frame sprite rendering to ST7789, shared tactical view + HUD, cursor, `Space` freeze, `P` view switch | **compiled + emulator-verified; on-device check pending** |
|
||||
| M2 — Network Graph & Traces | Node graph in Network view (door nodes on bulkhead tiles), link routing, ICE crack, red trace + `X` sever | planned |
|
||||
| M2 — Network Graph & Traces | 4-node sub-net in shared space (AIRLK→JUNC→DOOR/HIVE), animated link routing (1.5 s / 3.0 s ICE), door control, red trace → feedback spike + OVERHEAT, `X` sever, `R` reset | **done (emulator-verified)** |
|
||||
| M3 — Squad vs. Droids | Ship floorplan in Cameras view, 3 marines → beacon, 4 droids, gunfire | planned |
|
||||
| M4 — Cyber-Physical Bridge | Hive link + `1` FRENZY.EXE turns droids on each other (shared coordinate space) | planned |
|
||||
|
||||
@@ -56,3 +56,35 @@ milestone lands.
|
||||
4. `Space` freezes (CRT scanlines, sim/packets halt); cursor stays live.
|
||||
5. Trackball: smooth momentum cursor, tile snap in Cameras, node targeting
|
||||
in Network; Enter = beacon drop / node select; screen tap works too.
|
||||
|
||||
## M2 (done — emulator-verified)
|
||||
|
||||
Implements the sub-net half of the MVP vertical slice (`MVP.md` §1–§3,
|
||||
validation spec added in this commit) on the shared 320x192 coordinate space:
|
||||
|
||||
- **3-room floorplan** (airlock / main corridor / server room) with the
|
||||
Room2/Room3 blast door (`+`) and the objective terminal `T`.
|
||||
- **4-node sub-net** pinned to map tiles: AIRLK root (always online) —
|
||||
JUNC — DOOR_CTRL (on the blast door tile) / HIVE (3 s ICE). Click an
|
||||
adjacent offline node to route a link: animated dotted line turning
|
||||
solid over 1.5 s (3.0 s through ICE); offline until the build completes.
|
||||
- **DOOR_CTRL** (once online) toggles the blast door open/closed — open
|
||||
doors also un-block LOS/movement for the combat milestone.
|
||||
- **`X` severs the hovered link** (distance cursor→segment): everything
|
||||
beyond it drops, ICE progress resets; severing during a trace resets
|
||||
the trace safely.
|
||||
- **Red trace**: cracking HIVE spawns a 4 s red pulse back to AIRLK;
|
||||
arrival = feedback spike → all links drop + 3 s OVERHEAT lockout
|
||||
(`TEMP` bar). FRENZY/BLIND daemons are gated until a HIVE link is up
|
||||
(effects land in M4).
|
||||
- **`R` resets** the scenario instantly to the paused, re-armed state
|
||||
(`resetScenario()`), which also fixes the AIRLK-root-online bug.
|
||||
- Boot goes straight into the paused encounter; HUD shows daemon slots,
|
||||
TEMP bar, and `R: RESET`.
|
||||
- Emulator host (`emulator/src/main.cpp`): headless testing support —
|
||||
repeatable `--tap "x,y@frame"` screen-tap injection and repeatable
|
||||
`--type "text@frame"` scheduled keyboard input.
|
||||
- Verified headlessly: full route→door→ICE→trace→feedback→cooldown run,
|
||||
safe-sever run (trace reset, no spike), all gating messages
|
||||
(NO HIVE LINK / NO UPLINK / OVERHEAT / LINK SEVERED / NO NODE),
|
||||
and `r` reset; visual frame dumps inspected.
|
||||
|
||||
Reference in New Issue
Block a user