// Extra-zoom (closest / 4th level) KAT — verify-visuals-numerically, not by eye. The original's closest // zoom ("extra zoom") has no 4× sprite art: it renders the large (zoom-2) bank // and 2×-pixel-doubles it. Libreopolis's zoom 3 does the same — bank_zoom() caps the lookup at the large bank, // pix_scale()=2, and Framebuffer::blit_sprite draws each source pixel as a 2×2 block. Two checks: // 1. the 2× blit primitive (pure): scale=2 covers exactly the 2×2-per-pixel footprint. // 2. a real city renders at zoom 3 (not all-background, i.e. the large bank is actually found + doubled). // (The projection's zoom-3 = 2× zoom-2 invariant lives in test_iso_projection.) #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 #include #include using namespace sc2k; using namespace sc2k::render; #include "test_harness.hpp" #include "test_paths.hpp" struct GreyPal { Rgba operator[](int i) const { return Rgba{std::uint8_t(i), std::uint8_t(i), std::uint8_t(i), 0xFF}; } }; static bool is(Rgba c, std::uint8_t v) { return c.r == v && c.g == v && c.b == v; } static long count_drawn(const Framebuffer& fb) { // pixels not equal to the cleared city background long n = 0; for (int y = 0; y < fb.height(); ++y) for (int x = 0; x < fb.width(); ++x) { const Rgba c = fb.at(x, y); if (c.r != kBackground.r || c.g != kBackground.g || c.b != kBackground.b) ++n; } return n; } int main() { // ── 1. The 2× blit primitive (pure) ────────────────────────────────────────────────────────────── { Sprite s; s.width = 2; s.height = 3; s.index.assign(6, 5); s.mask.assign(6, 1); // 2×3, every pixel opaque, palette index 5 → grey 5 GreyPal pal; Framebuffer one(40, 40), two(40, 40); one.clear(Rgba{0, 0, 0, 0xFF}); two.clear(Rgba{0, 0, 0, 0xFF}); one.blit_sprite(s, 10, 10, false, pal, 1); two.blit_sprite(s, 10, 10, false, pal, 2); long n1 = 0, n2 = 0; for (int y = 0; y < 40; ++y) for (int x = 0; x < 40; ++x) { if (is(one.at(x, y), 5)) ++n1; if (is(two.at(x, y), 5)) ++n2; } CHECK(n1 == 6); // 2×3 at 1× CHECK(n2 == 24); // 4×6 at 2× — exactly four pixels each // scale=1 footprint is (10..11, 10..12); scale=2 is (10..13, 10..15), each source px a 2×2 block. CHECK(is(two.at(10, 10), 5) && is(two.at(11, 10), 5) && is(two.at(10, 11), 5) && is(two.at(11, 11), 5)); CHECK(is(two.at(13, 15), 5)); // bottom-right of the doubled sprite CHECK(!is(two.at(14, 10), 5) && !is(two.at(10, 16), 5)); // and nothing past its 4×6 extent } // ── 2. A real city renders at the extra zoom (skips without the art) ────────────────────────────── const std::string src = city_file("TOKYO.SC2"); if (!exists(src) || !have_render_assets()) { std::printf("zoom: (skip render — no TOKYO/art)\n"); } else { City city; CHECK(io::load_sc2(src, city).ok); Assets a = load_assets(); CityRenderer renderer(a.bank, a.palette); const int W = 900, H = 640; const int alt = int(city.altm.at(63, 63)) & 0x1F; long drawn[4] = {0, 0, 0, 0}; for (int z = 0; z <= 3; ++z) { // every zoom, incl. the extra (3) Framebuffer fb(W, H); const ScreenPos o = origin_centering_tile(63, 63, alt, z, W / 2, H / 2); renderer.render(city, fb, Camera{o.x, o.y}, /*compass=*/0, /*anim=*/0, z, {}); drawn[z] = count_drawn(fb); } for (int z = 0; z <= 3; ++z) CHECK(drawn[z] > 20000); // each zoom draws a substantial city // The bug this guards: zoom 3 looking up ids 1500+ → null → an all-background frame. It draws a // comparable amount to zoom 2 (same large art, fewer tiles but each 4× the area). CHECK(drawn[3] > drawn[2] / 2); std::printf("zoom: render drawn-px far/med/large/extra = %ld/%ld/%ld/%ld\n", drawn[0], drawn[1], drawn[2], drawn[3]); } if (failures == 0) { std::printf("zoom: extra-zoom 2× blit + render OK\n"); return 0; } std::printf("zoom: %d failure(s)\n", failures); return 1; }