// Numeric tests for the three view features wired in 2026-06-23 (verify-visuals-numerically, not by eye): // 1. Show/Hide layer toggles (toolbar 28-32) — // the renderer's ViewToggles gate Buildings (XBLD>=0x70), Infrastructure (0x01..0x6f) and the // zone-tint, and Underground swaps to a lowered dirt pipes/subway view and suppresses the surface. // 2. The rotate-then-recentre invariant (Rotate CCW/CW buttons): the tile under // the screen centre stays centred *at its altitude* across a quarter-turn — the height-correct // re-centring the buttons need. Built from the same public primitives the app's rotate_view uses. // 3. The Centering-tool invariant: centring on a clicked tile lands it dead-centre at its altitude. // // Part 2/3 are pure math (always run). Part 1 needs the extracted Win95 art, so it SKIPs without it. #include "sc2k/io/sc2_file.hpp" #include "sc2k/render/asset_loader.hpp" #include "sc2k/render/city_renderer.hpp" #include "sc2k/render/iso_projection.hpp" #include "sc2k/render/rotate.hpp" #include #include #include using namespace sc2k; using namespace sc2k::render; #include "test_harness.hpp" #include "test_paths.hpp" // Count pixels that differ between two framebuffers (same size). static long diff_px(const Framebuffer& a, const Framebuffer& b) { long n = 0; for (int y = 0; y < a.height(); ++y) for (int x = 0; x < a.width(); ++x) { const Rgba p = a.at(x, y), q = b.at(x, y); if (p.r != q.r || p.g != q.g || p.b != q.b) ++n; } return n; } struct RecordingTarget { struct Command { const Sprite* sprite = nullptr; int x = 0; int y = 0; bool highlightable = false; bool selectionOnly = false; int ownerRow = -1; int ownerCol = -1; }; std::vector commands; void clear(Rgba) { commands.clear(); } template void blit_sprite(const Sprite& sprite, int x, int y, bool, const PaletteLike&, int = 1) { commands.push_back({&sprite, x, y, false, false, -1, -1}); } template void blit_highlightable_sprite(const Sprite& sprite, int x, int y, bool, const PaletteLike&, int, int ownerRow, int ownerCol, bool) { commands.push_back({&sprite, x, y, true, false, ownerRow, ownerCol}); } template void blit_selection_sprite(const Sprite& sprite, int x, int y, bool, const PaletteLike&, int, int ownerRow, int ownerCol, bool) { commands.push_back({&sprite, x, y, true, true, ownerRow, ownerCol}); } void blit_shadow(const Sprite& sprite, int x, int y, bool, int = 1) { commands.push_back({&sprite, x, y, false, false, -1, -1}); } }; int main() { // ───────────────────────── Part 2: rotate-then-recentre keeps the focus tile centred ───────────── // This is exactly what app/main.cpp's `rotate_view` + `center_on_tile` compose. We replicate that // composition from the public primitives and assert the pivot tile lands on the screen centre at its // altitude after the turn — for every rotation, zoom and a spread of altitudes. (origin_centering_tile // is the exact inverse of tile_to_screen; rotation must carry the altitude with the tile.) const int CX = 640, CY = 400; // an arbitrary screen centre for (int rot = 0; rot < 4; ++rot) for (int zoom = 0; zoom <= 2; ++zoom) for (int alt : {0, 1, 7, 16, 31}) for (auto rc : {std::pair{63, 63}, std::pair{40, 70}, std::pair{0, 0}, std::pair{127, 0}}) { const int cr = rc.first, cc = rc.second; // city tile → its position in the view rotated `rot` quarter-turns CW int vr, vc; rotate_index_cw_n(cr, cc, rot, vr, vc); // app reads the altitude from the *rotated* view; rotation must preserve it per-tile, // so the centred camera = origin_centering_tile(view tile, that altitude). const ScreenPos cam = origin_centering_tile(vr, vc, alt, zoom, CX, CY); const ScreenPos p = tile_to_screen(vr, vc, alt, zoom, cam.x, cam.y); CHECK(p.x == CX && p.y == CY); // the focus tile is dead-centre, altitude included } // Rotation actually moves the altitude with the tile (so the centring above used the right height): // a synthetic city with a few raised tiles, rotated, must carry each altitude to the tile's new index. { City c; // zero-init layers c.altm.at(10, 20) = 7; c.altm.at(63, 63) = 16; c.altm.at(0, 127) = 31; for (int rot = 1; rot <= 3; ++rot) { const City r = rotate_city(c, rot); for (auto rc : {std::pair{10, 20}, std::pair{63, 63}, std::pair{0, 127}}) { int vr, vc; rotate_index_cw_n(rc.first, rc.second, rot, vr, vc); CHECK((r.altm.at(vr, vc) & 0x1F) == (c.altm.at(rc.first, rc.second) & 0x1F)); } } } std::printf("view_toggles: centring/rotation projection invariant — checked all rot/zoom/alt\n"); // ───────────────────────── Part 1: the renderer's Show/Hide layer toggles ───────────────────────── // Needs the extracted classic art (loose sprites + palette); SKIPs without it. if (!have_render_assets()) { std::printf("view_toggles: render-gating SKIP (no extracted assets — run extract_assets.py)\n"); if (failures == 0) { std::printf("view_toggles: all (math) checks passed\n"); return 0; } std::printf("view_toggles: %d failure(s)\n", failures); return 1; } const Assets a = load_assets(); CityRenderer renderer(a.bank, a.palette); // A BLANK flat city (all-zero layers = flat grass, alt 0, no water) carrying exactly one of each // toggle-able feature, so flipping a single toggle changes precisely that feature — nothing else on // the map to occlude or confound the diff. City city; int bcode = -1; for (int code = 0x70; code <= 0xFF; ++code) if (sim::building_sizes()[code] == 1 && a.bank.get(1000 + code)) { bcode = code; break; } CHECK(bcode > 0); const int bldR = 68, bldC = 68; // the lone building const int roadR = 66, roadC = 62; // the lone road (infra, XBLD 0x01..0x6f) const int zoneR = 62, zoneC = 66; // a zoned-but-undeveloped tile (→ zone tint) city.xbld.at(bldR, bldC) = std::uint8_t(bcode); city.xzon.at(bldR, bldC) = 0xF0; // 1×1 corner bits — a developed tile draws at its anchor bit city.xbld.at(roadR, roadC) = 0x1D; // a road straight city.xzon.at(zoneR, zoneC) = 0x01; // residential zone nibble, no building → tint Framebuffer fbOn(4200, 2600); const Camera cam{2100, 420}; renderer.render(city, fbOn, cam, 0, 0, 2, ViewToggles{}); // Buildings OFF (both building categories) — only the lone building differs, so the whole diff is that sprite. { Framebuffer fb(4200, 2600); renderer.render(city, fb, cam, 0, 0, 2, ViewToggles{.zonedBuildings = false, .otherBuildings = false}); const long ch = diff_px(fbOn, fb); std::printf("view_toggles: Buildings off — changed=%ld px (the lone structure)\n", ch); CHECK(ch > 50); // the building visibly vanished } // Transportation OFF — the road sprite is gone (terrain shows through), so the image changes. { Framebuffer fb(4200, 2600); renderer.render(city, fb, cam, 0, 0, 2, ViewToggles{.transportation = false}); const long ch = diff_px(fbOn, fb); std::printf("view_toggles: Transportation off — changed=%ld\n", ch); CHECK(ch > 10); // the road vanished } // A hidden multi-tile elevated deck must reveal ALL four terrain tiles. The front-most tile is // normally held back and drawn with the deck so it cannot cut across the road; retaining that // holdback after Transportation is hidden leaves a background-coloured diamond. { City blank; City deck; for (int dr = 0; dr < 2; ++dr) for (int dc = 0; dc < 2; ++dc) deck.xbld.at(60 + dr, 61 - dc) = 0x61; const ViewToggles no_transport{.transportation = false}; Framebuffer expected(4200, 2600), hidden(4200, 2600); renderer.render(blank, expected, cam, 0, 0, 2, no_transport); renderer.render(deck, hidden, cam, 0, 0, 2, no_transport); const long ch = diff_px(expected, hidden); std::printf("view_toggles: hidden elevated deck exposes complete terrain — changed=%ld\n", ch); CHECK(ch == 0); } // Zones OFF — the zone-tint tile reverts to terrain, so the image changes there. { Framebuffer fb(4200, 2600); renderer.render(city, fb, cam, 0, 0, 2, ViewToggles{.zones = false}); const long ch = diff_px(fbOn, fb); std::printf("view_toggles: Zones off — changed=%ld\n", ch); CHECK(ch > 5); // the zone tint reverted to bare terrain } // The 4→7 split is real: a road (Transport), power line (Power) and tree (Flora) each hide under // their OWN toggle, independently — proven by the three off-renders differing from one another. { City c3; c3.xbld.at(66, 62) = 0x1D; // road → Transport c3.xbld.at(66, 64) = 0x0E; // power line → Power c3.xbld.at(64, 62) = 0x06; // tree → Flora Framebuffer allOn(4200, 2600), noT(4200, 2600), noP(4200, 2600), noF(4200, 2600); renderer.render(c3, allOn, cam, 0, 0, 2, ViewToggles{}); renderer.render(c3, noT, cam, 0, 0, 2, ViewToggles{.transportation = false}); renderer.render(c3, noP, cam, 0, 0, 2, ViewToggles{.powerLines = false}); renderer.render(c3, noF, cam, 0, 0, 2, ViewToggles{.flora = false}); CHECK(diff_px(allOn, noT) > 0); // each toggle hides its own feature CHECK(diff_px(allOn, noP) > 0); CHECK(diff_px(allOn, noF) > 0); CHECK(diff_px(noT, noP) > 0); // …and they hide DIFFERENT features CHECK(diff_px(noT, noF) > 0); CHECK(diff_px(noP, noF) > 0); std::printf("view_toggles: 7-way split — road/power/flora hide independently\n"); } // Underground ON — grey backdrop, and the whole surface (buildings/infra/zone) is suppressed. { Framebuffer fb(4200, 2600); renderer.render(city, fb, cam, 0, 0, 2, ViewToggles{.underground = true}); // A corner pixel (well outside the diamond) is the underground grey, not the surface dark-brown. const Rgba corner = fb.at(2, 2); CHECK(corner.r == kUnderground.r && corner.g == kUnderground.g && corner.b == kUnderground.b); const long ch = diff_px(fbOn, fb); std::printf("view_toggles: Underground on — corner=(%d,%d,%d) changed=%ld\n", corner.r, corner.g, corner.b, ch); CHECK(ch > 100000); // a whole-view mode switch (bg + suppressed surface) } // ───────────────────────── Part 4: underground (x-ray) view CONTENT ─────────────────────────────── // The underground view draws a lowered dirt terrain floor, then water pipes + subway tunnels + // zone-coloured building outlines. Verify each numerically (not by eye): a feature toggled on a // single tile changes precisely that tile vs an otherwise-identical bare render. { const ViewToggles ug{.underground = true}; auto ug_render = [&](auto setup) { // fresh flat city → underground render City c; setup(c); Framebuffer fb(4200, 2600); renderer.render(c, fb, cam, 0, 0, 2, ug); return fb; }; const int pR = 60, pC = 60, sR = 60, sC = 64, tR = 64, tC = 60, rR = 64, rC = 64; // (a) opaque dirt terrain actually fills the diamond (the view isn't bare grey backdrop). Framebuffer bare = ug_render([](City&) {}); long nonGrey = 0; for (int y = 0; y < bare.height(); ++y) for (int x = 0; x < bare.width(); ++x) { const Rgba p = bare.at(x, y); if (!(p.r == kUnderground.r && p.g == kUnderground.g && p.b == kUnderground.b)) ++nonGrey; } CHECK(nonGrey > 10000); // the dirt terrain floor // (b) a pipe (XUND 0x10) and a subway (XUND 0x01) each draw distinct content vs bare, and ≠ each other. Framebuffer fPipe = ug_render([&](City& c) { c.xund.at(pR, pC) = 0x10; }); Framebuffer fSub = ug_render([&](City& c) { c.xund.at(sR, sC) = 0x01; }); CHECK(diff_px(bare, fPipe) > 0); CHECK(diff_px(bare, fSub) > 0); CHECK(diff_px(fPipe, fSub) > 0); // (c) SURFACE features contribute nothing underground — trees, roads, rail, power lines and // elevated highways all vanish (no value in surface infra down here); the only sub-0x70 // piece that shows is the subway↔rail adapter (Subways layer). Road-tunnel mouths are // surface transportation and disappear with their underground bores. for (int code : {0x06, 0x1D, 0x2C, 0x0E, 0x65}) CHECK(diff_px(bare, ug_render([&](City& c) { c.xbld.at(rR, rC) = std::uint8_t(code); })) == 0); Framebuffer fMouth = ug_render([&](City& c) { c.xbld.at(tR, tC) = 0x3F; }); Framebuffer fAdapter = ug_render([&](City& c) { c.xbld.at(rR, rC) = 0x6C; }); CHECK(diff_px(bare, fMouth) == 0); CHECK(diff_px(bare, fAdapter) > 0); // (d) zone-coloured outlines: R/C/I give three DISTINCT outlines, each ≠ bare and // ≠ a no-zone building — the blue=C / green=R / yellow=I / orange=other mapping is wired. auto bld = [&](int znib) { return ug_render([&](City& c) { c.xbld.at(bldR, bldC) = std::uint8_t(bcode); c.xzon.at(bldR, bldC) = std::uint8_t(znib); }); }; Framebuffer fR = bld(1), fC = bld(3), fI = bld(5), f0 = bld(0); CHECK(diff_px(bare, fR) > 0); // an outline appears over the building CHECK(diff_px(fR, fC) > 0); CHECK(diff_px(fR, fI) > 0); CHECK(diff_px(fC, fI) > 0); // R≠C≠I CHECK(diff_px(fR, f0) > 0); // zoned ≠ no-zone (orange) // (e) the outlines ALWAYS draw underground — the above-ground visibility toggles don't apply // down here (their checkboxes grey out), so the layout stays readable regardless. Framebuffer fOff(4200, 2600); { City c; c.xbld.at(bldR, bldC) = std::uint8_t(bcode); c.xzon.at(bldR, bldC) = 1; renderer.render(c, fOff, cam, 0, 0, 2, ViewToggles{.zonedBuildings = false, .otherBuildings = false, .underground = true}); } CHECK(diff_px(fR, fOff) == 0); std::printf("view_toggles: underground content — dirt nonGrey=%ld; pipe/subway/R/C/I " "outlines all distinct; surface infra and road tunnels hidden; outlines ignore surface toggles\n", nonGrey); } // The terrain floor is a distinct first pass, lowered by exactly one altitude level. Underground // infrastructure then uses that floor as an ordinary surface-overlay plane, like a road on terrain. // This pins command order and geometry directly, independent of opaque-pixel overlap in a screenshot. { City c; constexpr int row = 60, col = 60; c.xund.at(row, col) = 0x10; RecordingTarget target; renderer.render(c, target, cam, 0, 0, 2, ViewToggles{.underground = true}); const Sprite* dirt = a.bank.get(kTileSpriteBase + underground_dirt_terrain_code(0)); const Sprite* pipeSprite = a.bank.get(kTileSpriteBase + 318 + 0x10); CHECK(dirt && pipeSprite); std::size_t dirtCount = 0, pipeCount = 0, lastDirt = 0, firstPipe = target.commands.size(); const RecordingTarget::Command* dirtAtTile = nullptr; const RecordingTarget::Command* pipeAtTile = nullptr; const ScreenPos dirtProjection = tile_to_screen(row, col, -1, 2, cam.x, cam.y); const int expectedDirtY = dirtProjection.y - (dirt ? dirt->height - 17 : 0); for (std::size_t i = 0; i < target.commands.size(); ++i) { if (target.commands[i].sprite == dirt) { ++dirtCount; lastDirt = i; if (target.commands[i].x == dirtProjection.x && target.commands[i].y == expectedDirtY) dirtAtTile = &target.commands[i]; } if (target.commands[i].sprite == pipeSprite) { ++pipeCount; firstPipe = std::min(firstPipe, i); pipeAtTile = &target.commands[i]; } } CHECK(dirtCount == std::size_t(City::kDim) * City::kDim); CHECK(pipeCount == 1); CHECK(lastDirt < firstPipe); // complete terrain pass precedes infrastructure CHECK(dirtAtTile && pipeAtTile); if (dirtAtTile && pipeAtTile && dirt && pipeSprite) { const int dirtAnchorY = dirtAtTile->y + dirt->height - 17; const int pipeAnchorY = pipeAtTile->y + pipeSprite->height - 17; CHECK(dirtAnchorY == pipeAnchorY); } std::printf("view_toggles: underground terrain and infrastructure share one lowered surface plane\n"); } // A subway segment remains the foreground picking surface, but its cyan hover coverage belongs to // the lowered floor beneath it. Keeping those as separate commands lets transparent replacement art // reveal the selection while the network itself occludes it; it also prevents the baked legacy tile // top from appearing to hover at the old terrain elevation. { City c; constexpr int row = 60, col = 60; c.xund.at(row, col) = 0x01; RecordingTarget target; renderer.render(c, target, cam, 0, 0, 2, ViewToggles{.subways = true, .waterPipes = false, .underground = true}); const Sprite* dirt = a.bank.get(kTileSpriteBase + underground_dirt_terrain_code(0)); const Sprite* subway = a.bank.get(kTileSpriteBase + 318 + 0x01); CHECK(dirt && subway); const ScreenPos floorProjection = tile_to_screen(row, col, -1, 2, cam.x, cam.y); const int expectedFloorY = floorProjection.y - (dirt ? dirt->height - 17 : 0); std::size_t selectionIndex = target.commands.size(); std::size_t subwayIndex = target.commands.size(); const RecordingTarget::Command* subwayCommand = nullptr; for (std::size_t i = 0; i < target.commands.size(); ++i) { const RecordingTarget::Command& command = target.commands[i]; if (command.sprite == dirt && command.x == floorProjection.x && command.y == expectedFloorY && command.highlightable && command.ownerRow == row && command.ownerCol == col) selectionIndex = i; if (command.sprite == subway) { subwayIndex = i; subwayCommand = &command; CHECK(!command.highlightable); } } CHECK(selectionIndex < subwayIndex); CHECK(subwayIndex < target.commands.size()); if (selectionIndex < target.commands.size()) CHECK(target.commands[selectionIndex].selectionOnly); if (subwayCommand && subway) CHECK(subwayCommand->y + subway->height - 17 == floorProjection.y); std::printf("view_toggles: subway hover coverage is on the lowered floor beneath foreground art\n"); } // Terrain provenance selects the underground material explicitly. A generated/native cache uses // procedural earth + its deep cutaway skirt; the same canonical geometry marked as a classic // import remains on compatibility dirt art. This prevents native maps from silently inheriting // the legacy underground presentation merely because both project through City. { const Assets modernAssets = load_assets(assets_dir(), "grassland"); CHECK(modernAssets.terrain_material.has_value()); City c; std::vector vertices( std::size_t(City::kDim + 1) * (City::kDim + 1), 4 * terrain::kHeightQuantum); const auto model = terrain::Model::create( {City::kDim, City::kDim}, std::move(vertices)); CHECK(model.has_value()); const auto modernCache = model ? TerrainRenderCache::create(*model, c) : std::optional{}; const auto legacyCache = model ? TerrainRenderCache::create(*model, c, nullptr, nullptr, true) : std::optional{}; CHECK(modernCache && legacyCache); if (modernAssets.terrain_material && modernCache && legacyCache) { c.xund.at(60, 60) = 0x01; CityRenderer modernRenderer( modernAssets.bank, modernAssets.palette, &*modernAssets.terrain_material); RecordingTarget modernTarget, legacyTarget; modernRenderer.render(c, modernTarget, cam, 0, 0, 2, ViewToggles{.underground = true}, {}, {}, &*modernCache); modernRenderer.render(c, legacyTarget, cam, 0, 0, 2, ViewToggles{.underground = true}, {}, {}, &*legacyCache); const TerrainRenderTile modernTile = TerrainRenderView(c, &*modernCache).tile(60, 60); const Sprite* modernFloor = &modernAssets.terrain_material->underground_surface_sprite( modernTile, 60, 60, 2); const TerrainRenderTile edgeTile = TerrainRenderView(c, &*modernCache).tile(City::kDim - 1, City::kDim - 1); const Sprite* modernSkirt = &modernAssets.terrain_material->underground_skirt_sprite( edgeTile, true, true, 2); const Sprite* legacyDirt = modernAssets.bank.get( kTileSpriteBase + underground_dirt_terrain_code(0)); const auto contains = [](const RecordingTarget& target, const Sprite* sprite) { return std::any_of(target.commands.begin(), target.commands.end(), [&](const RecordingTarget::Command& command) { return command.sprite == sprite; }); }; CHECK(contains(modernTarget, modernFloor)); CHECK(contains(modernTarget, modernSkirt)); CHECK(!contains(modernTarget, legacyDirt)); CHECK(!contains(legacyTarget, modernFloor)); CHECK(!contains(legacyTarget, modernSkirt)); CHECK(contains(legacyTarget, legacyDirt)); const auto hasSelection = [](const RecordingTarget& target, const Sprite* sprite) { return std::any_of(target.commands.begin(), target.commands.end(), [&](const RecordingTarget::Command& command) { return command.sprite == sprite && command.highlightable && command.selectionOnly && command.ownerRow == 60 && command.ownerCol == 60; }); }; CHECK(hasSelection(modernTarget, modernFloor)); CHECK(hasSelection(legacyTarget, legacyDirt)); } std::printf("view_toggles: native underground material/skirt are distinct from classic imports\n"); } // ───────────────────────── Part 4b: underground networks + water coverage ───────────────────────── // The low-level toggles can still isolate either network for renderer tests. The Water pipes layer // draws player-built mains and sources, while consumer tiles communicate capillary results through // supplied/needed floor colours instead of thousands of tiny pipe sprites. { auto ug = [&](ViewToggles t, auto setup) { t.underground = true; City c; setup(c); Framebuffer fb(4200, 2600); renderer.render(c, fb, cam, 0, 0, 2, t); return fb; }; const int pR = 60, pC = 60, sR = 60, sC = 64; auto pipe = [&](City& c) { c.xund.at(pR, pC) = 0x10; }; auto subway = [&](City& c) { c.xund.at(sR, sC) = 0x01; }; // A pipe vanishes with Water pipes off; a subway with Subways off — and each toggle leaves the // OTHER network untouched (independent gating). CHECK(diff_px(ug(ViewToggles{}, pipe), ug(ViewToggles{.waterPipes = false}, pipe)) > 0); CHECK(diff_px(ug(ViewToggles{}, subway), ug(ViewToggles{.subways = false}, subway)) > 0); CHECK(diff_px(ug(ViewToggles{}, subway), ug(ViewToggles{.waterPipes = false}, subway)) == 0); CHECK(diff_px(ug(ViewToggles{}, pipe), ug(ViewToggles{.subways = false}, pipe)) == 0); // The surface-to-subway adapter is underground content too, so it uses the lowered surface // rather than retaining the surface map's original elevation. { City c; c.xbld.at(pR, pC) = xbld::kSubRailFirst; RecordingTarget target; renderer.render(c, target, cam, 0, 0, 2, ViewToggles{.underground = true}); const Sprite* adapter = a.bank.get(kTileSpriteBase + xbld::kSubRailFirst); const RecordingTarget::Command* adapterCommand = nullptr; for (const RecordingTarget::Command& command : target.commands) if (command.sprite == adapter) adapterCommand = &command; CHECK(adapterCommand && adapter); if (adapterCommand && adapter) { const ScreenPos floorProjection = tile_to_screen(pR, pC, -1, 2, cam.x, cam.y); CHECK(adapterCommand->y + adapter->height - 17 == floorProjection.y); } } // A water pump (0xDC, an "Other building") stays visible with Other buildings OFF as long as Water // pipes is ON — so pumps are traceable; it hides only when BOTH are off. auto pump = [&](City& c) { c.xbld.at(pR, pC) = 0xDC; }; Framebuffer bareUG = ug(ViewToggles{}, [](City&) {}); Framebuffer pumpOn = ug(ViewToggles{}, pump); // Water pipes on → real sprite + foundation Framebuffer pumpOff = ug(ViewToggles{.waterPipes = false}, pump); // off → the always-on outline CHECK(diff_px(bareUG, pumpOn) > 0); CHECK(diff_px(bareUG, pumpOff) > 0); CHECK(diff_px(pumpOn, pumpOff) > 0); // sprite+foundation ≠ plain outline // Player-built mains use one static shape whether or not they currently carry water. The old // flowing-water variant made the entire network shimmer even though coverage now owns that state. auto manualMain = [&](std::uint8_t bits) { return ug(ViewToggles{.subways = false}, [&](City& c) { c.xund.at(pR, pC) = 0x10; c.xbit.at(pR, pC) = bits; }); }; CHECK(diff_px(manualMain(xbit::kPipe), manualMain(xbit::kPipe | xbit::kWatered)) == 0); // A capillary is only the XBIT pipe flag beneath a developed building. Toggling that flag no // longer changes pixels; water result does. The centre of the same terrain diamond shifts from // warm unmet coverage to blue supplied coverage, and the building's zone outline stays above it. auto consumer = [&](std::uint8_t bits) { return ug(ViewToggles{.subways = false}, [&](City& c) { c.xbld.at(pR, pC) = std::uint8_t(bcode); c.xzon.at(pR, pC) = 0x81; c.xbit.at(pR, pC) = bits; }); }; Framebuffer neededNoPipe = consumer(0); Framebuffer neededPipe = consumer(xbit::kPipe); Framebuffer suppliedNoPipe = consumer(xbit::kWatered); Framebuffer suppliedPipe = consumer(xbit::kPipe | xbit::kWatered); CHECK(diff_px(neededNoPipe, neededPipe) == 0); CHECK(diff_px(suppliedNoPipe, suppliedPipe) == 0); CHECK(diff_px(neededPipe, suppliedPipe) > 0); const ScreenPos coverageCentre = diamond_centre( tile_to_screen(pR, pC, -1, 2, cam.x, cam.y), 2); const Rgba neededColour = neededPipe.at(coverageCentre.x, coverageCentre.y); const Rgba suppliedColour = suppliedPipe.at(coverageCentre.x, coverageCentre.y); CHECK(neededColour.r > neededColour.b); CHECK(suppliedColour.b > suppliedColour.r); // Pure water mode communicates demand exclusively through floor colour; surface zone // categories and their outlines do not leak into this infrastructure view. { City c; c.modernWaterSystem = true; c.xbld.at(pR, pC) = std::uint8_t(bcode); c.xzon.at(pR, pC) = 0x81; RecordingTarget target; renderer.render(c, target, cam, 0, 0, 2, ViewToggles{.subways = false, .waterPipes = true, .underground = true}); const Sprite* outline = a.bank.get( kTileSpriteBase + underground_zone_outline_code(c.xzon.at(pR, pC))); CHECK(std::none_of(target.commands.begin(), target.commands.end(), [&](const RecordingTarget::Command& command) { return command.sprite == outline; })); } // The lowered dirt tile owns the selection/zone plane; visible networks paint over that plane. // This reverses the old x-ray ordering, where the building outline hid pipes and subways. { City c; c.xbld.at(pR, pC) = std::uint8_t(bcode); c.xzon.at(pR, pC) = 0x81; c.xund.at(pR, pC) = 0x10; RecordingTarget target; renderer.render(c, target, cam, 0, 0, 2, ViewToggles{.underground = true}); const Sprite* outline = a.bank.get( kTileSpriteBase + underground_zone_outline_code(c.xzon.at(pR, pC))); const Sprite* pipeSprite = a.bank.get(kTileSpriteBase + 318 + 0x10); std::size_t outlineIndex = target.commands.size(); std::size_t pipeIndex = target.commands.size(); const RecordingTarget::Command* outlineCommand = nullptr; for (std::size_t i = 0; i < target.commands.size(); ++i) { if (target.commands[i].sprite == outline) { outlineIndex = std::min(outlineIndex, i); outlineCommand = &target.commands[i]; } if (target.commands[i].sprite == pipeSprite) pipeIndex = std::min(pipeIndex, i); } CHECK(outlineIndex < pipeIndex); CHECK(outlineCommand && outline); if (outlineCommand && outline) { const ScreenPos floorProjection = tile_to_screen(pR, pC, -1, 2, cam.x, cam.y); CHECK(outlineCommand->y + outline->height - 17 == floorProjection.y); } } // The surface subway station already receives the same one-level foundation as a pumping // station. Its legacy two-level underground platform must not be drawn underneath as well. { City c; c.xbld.at(pR, pC) = xbld::kSubwayStation; c.xzon.at(pR, pC) = 0x80; c.xund.at(pR, pC) = 0x23; RecordingTarget target; renderer.render(c, target, cam, 0, 0, 2, ViewToggles{.underground = true}); const Sprite* legacyStationDepth = a.bank.get( kTileSpriteBase + 318 + 0x23); const Sprite* oneLevelFoundation = a.bank.get(kTileSpriteBase + kTunnelBodySprite); int legacyDepthCount = 0; int foundationCount = 0; const RecordingTarget::Command* foundationCommand = nullptr; for (const RecordingTarget::Command& command : target.commands) { legacyDepthCount += command.sprite == legacyStationDepth; foundationCount += command.sprite == oneLevelFoundation; if (command.sprite == oneLevelFoundation) foundationCommand = &command; } CHECK(legacyDepthCount == 0); CHECK(foundationCount == 1); if (foundationCommand && oneLevelFoundation) { const ScreenPos floorProjection = tile_to_screen(pR, pC, -1, 2, cam.x, cam.y); CHECK(foundationCommand->y + oneLevelFoundation->height - 17 == floorProjection.y); } } // …and a MULTI-TILE source (water treatment) draws its sprite + per-tile foundation the same way. const int tN = sim::building_sizes()[0xF4]; auto plant = [&](City& c) { for (int dr = 0; dr < tN; ++dr) for (int dc = 0; dc < tN; ++dc) c.xbld.at(66 + dr, 66 - dc) = 0xF4; }; CHECK(diff_px(bareUG, ug(ViewToggles{}, plant)) > 0); CHECK(diff_px(ug(ViewToggles{}, plant), ug(ViewToggles{.waterPipes = false}, plant)) > 0); // Road tunnels do not belong in this view: neither their ALTM depth body nor the now-obsolete // Tunnels toggle changes underground output. auto tun = [&](City& c) { c.altm.at(58, 58) = std::uint16_t(c.altm.at(58, 58) | (3 << 10)); }; CHECK(diff_px(ug(ViewToggles{}, tun), ug(ViewToggles{.tunnels = false}, tun)) == 0); CHECK(diff_px(ug(ViewToggles{}, tun), ug(ViewToggles{}, [](City&) {})) == 0); CHECK(diff_px(ug(ViewToggles{}, pipe), ug(ViewToggles{.tunnels = false}, pipe)) == 0); // CROSSOVER tiles (XUND 0x1F/0x20 = subway + pipe on one tile) belong to BOTH networks: // something draws there under any single toggle (hiding pipes must NOT cut the subway line, // and vice versa), and the two single-network draws differ from each other. Framebuffer bare = ug(ViewToggles{}, [](City&) {}); auto xoverC = [&](City& c) { c.xund.at(62, 62) = 0x1F; }; Framebuffer xBoth = ug(ViewToggles{}, xoverC); Framebuffer xSub = ug(ViewToggles{.waterPipes = false}, xoverC); Framebuffer xPipe = ug(ViewToggles{.subways = false}, xoverC); CHECK(diff_px(bare, xBoth) > 0); // combined art draws CHECK(diff_px(bare, xSub) > 0); // subway half survives pipes-off CHECK(diff_px(bare, xPipe) > 0); // pipe half survives subways-off CHECK(diff_px(xSub, xPipe) > 0); // …and they are the two DIFFERENT halves std::printf("view_toggles: underground networks — static player mains; hidden capillaries; " "blue supplied / warm unmet coverage; sources legible; crossovers belong to both\n"); } // ───────────────────────── Part 4c: flat-terrace step faces are filled ──────────────────────────── // Saved cities carry runs of FLAT tiles stepping one ALTM level each (an original city's hillside). // The lower neighbour is flat, so no slope sprite rises to cover the step's vertical face, and the old // ≥2-level cliff rule left a hollow showing the background. Sample the face band under the upper // tile's bottom vertex: it must NOT be the background colour. { City c; for (int r = 0; r < City::kDim; ++r) for (int col = 0; col < City::kDim; ++col) c.altm.at(r, col) = std::uint16_t((r <= 64 && col <= 64) ? 5 : 4); // a flat terrace step Framebuffer fs(4200, 2600); renderer.render(c, fs, cam, 0, 0, 2, ViewToggles{}); const Rgba bgS = fs.at(2, 2); const ScreenPos ps = tile_to_screen(64, 64, 5, 2, cam.x, cam.y); const Rgba faceS = fs.at(ps.x + 16, ps.y + 22); // mid-face between the two surfaces CHECK(!(faceS.r == bgS.r && faceS.g == bgS.g && faceS.b == bgS.b)); std::printf("view_toggles: flat-terrace step face is filled (not background)\n"); } if (failures == 0) { std::printf("view_toggles: all checks passed\n"); return 0; } std::printf("view_toggles: %d failure(s)\n", failures); return 1; }