Something went wrong. Try again.
[Mirror] Libreopolis is a cross-platform city simulation game fully compatible with SimCity 2000. gitlab.com/conasg/libreopolis
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970// End-to-end render test: load a real city, composite it with the Win95 art, and verify the result// NUMERICALLY (not by eye, per feedback-verify-visuals-numerically): coverage and iso-diamond// geometry. Also drops a viewable BMP snapshot in build/ for manual inspection. Skips if no game data.#include "sc2k/io/sc2_file.hpp"#include "sc2k/render/asset_loader.hpp"#include "sc2k/render/city_renderer.hpp"#include "sc2k/render/connection_arrow.hpp"#include "sc2k/render/sign_layout.hpp" // sign geometry and house-style presentation#include "sc2k/sim/growth.hpp"#include "sc2k/ui/tools.hpp" // bridge_probe / bridge_lay / bridge_remove (faithful to the original)#include <cstdio>#include <string>#include <vector>
using namespace sc2k;using namespace sc2k::render;
#include "test_harness.hpp"#include "test_paths.hpp"
int main() { const std::string cityPath = first_present_city({"TOKYO.SC2", "LONDON.SC2", "NEWYORK.SC2", "PARIS.SC2", "BAYVIEW.SC2"}); if (cityPath.empty() || !have_render_assets()) { std::printf("city_render: SKIP (no city under %s or no extracted assets — run extract_assets.py)\n", test_root().c_str()); return 0; }
City city; const auto lr = io::load_sc2(cityPath, city); CHECK(lr.ok); if (!lr.ok) { std::printf("city_render: load failed: %s\n", lr.error.c_str()); return 1; }
const Assets a = load_assets(); CityRenderer renderer(a.bank, a.palette);
// ---- Visible structure picking + in-order masked highlight (synthetic flat city). ---- // A tower's opaque sprite pixels above every terrain diamond must select its one structure owner; // tinting that owner may alter only pixels which the painter-order hit index says remain visible. { City tower; CHECK(construct_building(tower, 60, 60, 251, 4, 0)); // a tall 4x4 arcology const ScreenPos centred = origin_centering_tile(61, 61, 0, 2, 450, 450); const Camera towerCam{centred.x, centred.y}; Framebuffer normal(900, 700); renderer.render(tower, normal, towerCam); ObjectSelection selected; for (int r = 60; r < 64 && !selected; ++r) for (int c = 60; c < 64 && !selected; ++c) selected = renderer.object_at_tile(r, c); CHECK(selected); for (int r = 60; r < 64; ++r) for (int c = 60; c < 64; ++c) CHECK(renderer.object_at_tile(r, c) == selected);
int selectedPixels = 0, selectedMinY = normal.height(); for (int y = 0; y < normal.height(); ++y) for (int x = 0; x < normal.width(); ++x) { const auto hit = renderer.visible_object_at(x - towerCam.x + 0.5, y - towerCam.y + 0.5); if (hit.hit && hit.object == selected) { ++selectedPixels; selectedMinY = std::min(selectedMinY, y); } } const ScreenPos anchorSurface = tile_to_screen(selected.row, selected.col, 0, 2, towerCam.x, towerCam.y); CHECK(selectedPixels > 1000); CHECK(selectedMinY < anchorSurface.y - 20); // the tower tip, not merely its ground diamond
Framebuffer highlighted(900, 700); renderer.render(tower, highlighted, towerCam, 0, 0, 2, {}, {}, {}, nullptr, selected); int changedPixels = 0, changedOutsideVisibleStructure = 0; for (int y = 0; y < normal.height(); ++y) for (int x = 0; x < normal.width(); ++x) { const Rgba before = normal.at(x, y), after = highlighted.at(x, y); if (before.r == after.r && before.g == after.g && before.b == after.b) continue; ++changedPixels; const auto hit = renderer.visible_object_at(x - towerCam.x + 0.5, y - towerCam.y + 0.5); if (!hit.hit || hit.object != selected) ++changedOutsideVisibleStructure; } CHECK(changedPixels > 1000); CHECK(changedOutsideVisibleStructure == 0); // foreground pixels remain untouched highlighted.write_bmp("build/structure_highlight.bmp"); std::printf("city_render: structure mask selected=%d px highlighted=%d px minY=%d surfaceY=%d\n", selectedPixels, changedPixels, selectedMinY, anchorSurface.y); }
// A connection arrow is inserted at its owning edge tile's painter position. A later/nearer // structure therefore conceals part of it rather than the marker floating over the whole city. { City occlusionCity{MapSize::Tiny}; CHECK(construct_building(occlusionCity, 31, 31, 251, 4, 0)); const ScreenPos centred = origin_centering_tile(31, 31, 0, 2, 320, 280); const Camera occlusionCamera{centred.x, centred.y}; Framebuffer withoutArrow(640, 520); renderer.render(occlusionCity, withoutArrow, occlusionCamera); const Sprite& arrow = connection_arrow_sprite(2, ConnectionArrowDirection::RowPositive); const std::size_t arrowCoverage = static_cast<std::size_t>(std::count(arrow.mask.begin(), arrow.mask.end(), std::uint8_t{1})); std::size_t partialVisibility = 0; for (int markerRow = 27; markerRow <= 30 && partialVisibility == 0; ++markerRow) { for (int markerColumn = 27; markerColumn <= 30 && partialVisibility == 0; ++markerColumn) { Framebuffer withArrow(640, 520); const std::vector<Decal> decals = {{markerRow, markerColumn, 0, 0, &arrow, 0}}; renderer.render(occlusionCity, withArrow, occlusionCamera, 0, 0, 2, {}, decals); std::size_t visible = 0; for (int y = 0; y < withArrow.height(); ++y) for (int x = 0; x < withArrow.width(); ++x) { const Rgba before = withoutArrow.at(x, y), after = withArrow.at(x, y); if (before.r != after.r || before.g != after.g || before.b != after.b) ++visible; } if (visible > 0 && visible < arrowCoverage) partialVisibility = visible; } } CHECK(partialVisibility > 0); std::printf("city_render: connection arrow visible=%zu/%zu px after foreground occlusion\n", partialVisibility, arrowCoverage); }
// A framebuffer sized to hold the whole 128x128 diamond at zoom 2 (x spans ~±2032 about camX). Framebuffer fb(4200, 2600); const Camera cam{2100, 420}; renderer.render(city, fb, cam);
// Coverage + bounding box of non-background pixels. long drawn = 0; int minX = fb.width(), maxX = -1, minY = fb.height(), maxY = -1; for (int y = 0; y < fb.height(); ++y) for (int x = 0; x < fb.width(); ++x) { const Rgba p = fb.at(x, y); const bool bg = p.r == kBackground.r && p.g == kBackground.g && p.b == kBackground.b; if (!bg) { ++drawn; if (x < minX) minX = x; if (x > maxX) maxX = x; if (y < minY) minY = y; if (y > maxY) maxY = y; } }
// The city clearly rendered (terrain alone fills a large diamond). CHECK(drawn > 500000);
// Iso geometry: a full 128-wide map spans (row-col) in [-127,127] -> x width ~ 254*16 = 4064 px. const int spanX = maxX - minX; const int spanY = maxY - minY; std::printf("city_render: %s drawn=%ld bbox=[%d..%d]x[%d..%d] spanX=%d spanY=%d\n", cityPath.c_str(), drawn, minX, maxX, minY, maxY, spanX, spanY); CHECK(spanX > 3800 && spanX < 4200); // the diamond's full width, ± sprite overhang CHECK(spanY > 1500); // (row+col) 0..254 -> ~2032 px tall minus overlap
// The diamond is horizontally centred on the camera origin (within a tile or two). const int centerX = (minX + maxX) / 2; CHECK(centerX > cam.x - 40 && centerX < cam.x + 40);
// ---- Disaster effect overlay: fire tiles composite their sprite on top of the city. ---- CHECK(a.bank.get(1396) != nullptr); // fire animation frames present in the archive CHECK(a.bank.get(1492) != nullptr && a.bank.get(1494) != nullptr && a.bank.get(1496) != nullptr); std::vector<Rgba> before(std::size_t(fb.width()) * fb.height()); for (int y = 0; y < fb.height(); ++y) for (int x = 0; x < fb.width(); ++x) before[std::size_t(y) * fb.width() + x] = fb.at(x, y); // Light a 6×6 block of the built area on fire (fire shows where it can sit). int fr = -1, fc = -1; for (int r = 0; r < City::kDim && fr < 0; ++r) for (int c = 0; c < City::kDim; ++c) if (city.xbld.at(r, c) >= 0x70) { fr = r; fc = c; break; } CHECK(fr >= 0); for (int r = fr; r < fr + 6 && r < City::kDim; ++r) for (int c = fc; c < fc + 6 && c < City::kDim; ++c) city.xtxt.at(r, c) = 0xFF; renderer.render(city, fb, cam, 0, /*anim=*/0); std::vector<Rgba> fire0(before.size()); long changed = 0; for (int y = 0; y < fb.height(); ++y) for (int x = 0; x < fb.width(); ++x) { const Rgba p = fb.at(x, y); fire0[std::size_t(y) * fb.width() + x] = p; const Rgba q = before[std::size_t(y) * fb.width() + x]; if (p.r != q.r || p.g != q.g || p.b != q.b) ++changed; } CHECK(changed > 200); // the fire block clearly drew its sprites // Animation: a different frame cycles the per-tile fire sprite, so the composite shifts. renderer.render(city, fb, cam, 0, /*anim=*/2); long animDiff = 0; for (int y = 0; y < fb.height(); ++y) for (int x = 0; x < fb.width(); ++x) { const Rgba p = fb.at(x, y), q = fire0[std::size_t(y) * fb.width() + x]; if (p.r != q.r || p.g != q.g || p.b != q.b) ++animDiff; } std::printf("city_render: fire overlay changed=%ld px, anim frame diff=%ld px\n", changed, animDiff); CHECK(animDiff > 0); // frames actually differ (animated fire)
// ---- Moving Things: a tornado (XTHG type 15) composites its funnel sprite (id 1499). ---- City tc; CHECK(io::load_sc2(cityPath, tc).ok); CHECK(a.bank.get(1499) != nullptr); // the tornado funnel sprite is in the archive Framebuffer tb(4200, 2600); renderer.render(tc, tb, cam); // baseline (no things) tc.xthg[1 * 12 + 0] = 15; // type 15 = tornado tc.xthg[1 * 12 + 3] = 64; tc.xthg[1 * 12 + 4] = 64; // at tile (64,64) Framebuffer tb2(4200, 2600); renderer.render(tc, tb2, cam); long tdiff = 0; for (int y = 0; y < tb.height(); ++y) for (int x = 0; x < tb.width(); ++x) { const Rgba p = tb.at(x, y), q = tb2.at(x, y); if (p.r != q.r || p.g != q.g || p.b != q.b) ++tdiff; } std::printf("city_render: tornado funnel drew %ld px\n", tdiff); CHECK(tdiff > 100); // the funnel sprite clearly composited
// ---- The monster (XTHG type 5) composites its big multi-piece sprite (ids 1478-1491). ---- City mc; CHECK(io::load_sc2(cityPath, mc).ok); CHECK(a.bank.get(1490) != nullptr || a.bank.get(1491) != nullptr); // head pieces present Framebuffer mb(4200, 2600); renderer.render(mc, mb, cam); // baseline mc.xthg[1 * 12 + 0] = 5; // type 5 = monster mc.xthg[1 * 12 + 3] = 64; mc.xthg[1 * 12 + 4] = 64; Framebuffer mb2(4200, 2600); renderer.render(mc, mb2, cam); long mdiff = 0; for (int y = 0; y < mb.height(); ++y) for (int x = 0; x < mb.width(); ++x) { const Rgba p = mb.at(x, y), q = mb2.at(x, y); if (p.r != q.r || p.g != q.g || p.b != q.b) ++mdiff; } std::printf("city_render: monster drew %ld px\n", mdiff); CHECK(mdiff > 1000); // the big composite clearly drew
// ---- A train (XTHG type 10) on a rail tile composites its car sprite (1374-1378, get_train_tile). ---- City trc; CHECK(io::load_sc2(cityPath, trc).ok); CHECK(a.bank.get(1374) != nullptr); // Clear a forward (nearer-diagonal) block so the train — a short, ground-level sprite — isn't OCCLUDED // by closer buildings now that Things draw INTERLEAVED per tile (the faithful per-tile overlay order); then // lay the rail it rides. (Same guard the traffic-car test uses below; occlusion itself is asserted in // the dedicated effect/Thing occlusion test.) for (int r = 64; r < 64 + 8; ++r) for (int c = 64; c < 64 + 8; ++c) { trc.xbld.at(r, c) = 0; trc.xbit.at(r, c) &= ~0x04; trc.xter.at(r, c) = 0; } for (auto& v : trc.xthg) v = 0; // drop the save's in-flight Things so only OUR train draws trc.xbld.at(64, 64) = 0x2C; // a rail straight under the train Framebuffer trb(4200, 2600); renderer.render(trc, trb, cam); // baseline (track, no train) trc.xthg[1 * 12 + 0] = 10; trc.xthg[1 * 12 + 3] = 64; trc.xthg[1 * 12 + 4] = 64; Framebuffer trb2(4200, 2600); renderer.render(trc, trb2, cam); long trdiff = 0; for (int y = 0; y < trb.height(); ++y) for (int x = 0; x < trb.width(); ++x) { const Rgba p = trb.at(x, y), q = trb2.at(x, y); if (p.r != q.r || p.g != q.g || p.b != q.b) ++trdiff; } std::printf("city_render: train car drew %ld px\n", trdiff); CHECK(trdiff > 50); // the train sprite clearly composited
// ---- Animated traffic: a busy road tile composites a car sprite (XTRF-gated). ---- CHECK(a.bank.get(1400) != nullptr); // the car sprite bank is present { City rc; CHECK(io::load_sc2(cityPath, rc).ok); const int rr = 64, rcc = 64; // Clear a forward (nearer-diagonal) block so the car isn't occluded by closer buildings, then // lay a straight road on the test tile. for (int r = rr; r < rr + 8; ++r) for (int c = rcc; c < rcc + 8; ++c) { rc.xbld.at(r, c) = 0; rc.xbit.at(r, c) &= ~0x04; rc.xter.at(r, c) = 0; } rc.xbld.at(rr, rcc) = 0x1D; Framebuffer q(4200, 2600), b(4200, 2600); rc.xtrf.at(rr / 2, rcc / 2) = 0; renderer.render(rc, q, cam); // road, no traffic rc.xtrf.at(rr / 2, rcc / 2) = 200; renderer.render(rc, b, cam); // road, heavy traffic → car long carPx = 0; for (int y = 0; y < q.height(); ++y) for (int x = 0; x < q.width(); ++x) { const Rgba p = q.at(x, y), z = b.at(x, y); if (p.r != z.r || p.g != z.g || p.b != z.b) ++carPx; } std::printf("city_render: traffic car drew %ld px\n", carPx); CHECK(carPx > 30); // the car sprite clearly composited over the road }
// ---- Bridges: an auto-spanned bridge composites ramp + deck sprites over water; removing // it takes them back off. Carve a clean E-W channel, lay a road suspension span, and // verify it drew, then that removal returns toward the open-water baseline. Crop → build/. ---- { City bc; CHECK(io::load_sc2(cityPath, bc).ok); for (auto& v : bc.xthg) v = 0; // no in-flight Things over the crossing const int R = 64, C = 62, W = 5; for (int r = R - 2; r <= R + 2; ++r) // bare flat land baseline around it for (int c = C - 2; c <= C + W + 1; ++c) { bc.xbld.at(r, c) = 0; bc.xzon.at(r, c) = 0; bc.xbit.at(r, c) = 0; bc.xter.at(r, c) = 0; bc.altm.at(r, c) = 5; } for (int r = R - 1; r <= R + 1; ++r) // a 3-tall E-W water channel, W tiles wide for (int c = C; c < C + W; ++c) { bc.xbit.at(r, c) = 0x04; bc.altm.at(r, c) = std::uint16_t(5 | (5 << 5)); bc.xter.at(r, c) = std::uint8_t((r == R && c == C) ? 0x22 : 0x12); // anchor coast → launch E } bc.xbld.at(R, C - 1) = 0x1D; bc.xbld.at(R, C + W) = 0x1D; // roads on both shores Framebuffer wb(4200, 2600); renderer.render(bc, wb, cam); // baseline: open water const auto sp = ui::detail::bridge_probe(bc, R, C, 2); CHECK(sp.status == ui::detail::BridgeStatus::Ok && sp.span == W); ui::detail::bridge_lay(bc, sp, /*suspension*/ 2); Framebuffer bb(4200, 2600); renderer.render(bc, bb, cam); auto diff_px = [](const Framebuffer& a0, const Framebuffer& b0) { long n = 0; for (int y = 0; y < a0.height(); ++y) for (int x = 0; x < a0.width(); ++x) { const Rgba p = a0.at(x, y), q = b0.at(x, y); if (p.r != q.r || p.g != q.g || p.b != q.b) ++n; } return n; }; const long bdiff = diff_px(wb, bb); ui::detail::bridge_remove(bc, R, C + 2); // bulldoze a deck → whole span razed Framebuffer rb(4200, 2600); renderer.render(bc, rb, cam); const long rdiff = diff_px(wb, rb); std::printf("city_render: bridge drew %ld px; after removal %ld px differ from open water\n", bdiff, rdiff); CHECK(bdiff > 200); // ramps + deck clearly composited over the water CHECK(rdiff < bdiff); // removal took most of the span back off // A viewable crop centred on the bridge. const ScreenPos mid = tile_to_screen(R, C + W / 2, 6, 2, cam.x, cam.y); Framebuffer crop(420, 300); for (int y = 0; y < crop.height(); ++y) for (int x = 0; x < crop.width(); ++x) { const int sx = mid.x - 210 + x, sy = mid.y - 150 + y; if (sx >= 0 && sy >= 0 && sx < bb.width() && sy < bb.height()) crop.set(x, y, bb.at(sx, sy)); } crop.write_bmp("build/city_bridge.bmp"); }
// ---- Power causeway ramps have the same composed presentation when XBLD explicitly stores their // slope-power pieces and when an imported map leaves those ramp XBLDs empty. ---- { City pc; const int R = 64, C = 60, W = 7, L = 5; pc.set_misc_be32(sc2k::misc::kWaterLevel, L + 1); for (int r = 0; r < City::kDim; ++r) for (int c = 0; c < City::kDim; ++c) { pc.xter.at(r, c) = 0; pc.xbld.at(r, c) = 0; pc.xzon.at(r, c) = 0; pc.xbit.at(r, c) = 0; pc.altm.at(r, c) = std::uint16_t(L + 2); } for (int r = R - 1; r <= R + 1; ++r) for (int c = C; c < C + W; ++c) { pc.xbit.at(r, c) = xbit::kWater; pc.altm.at(r, c) = std::uint16_t(L | ((L + 2) << 5)); pc.xter.at(r, c) = std::uint8_t((r == R && c == C) ? 0x22 : 0x12); } pc.xbld.at(R, C - 1) = xbld::kPowerFirst; pc.xbit.at(R, C - 1) = xbit::kConductive; pc.xbld.at(R, C + W) = xbld::kPowerFirst; pc.xbit.at(R, C + W) = xbit::kConductive; const auto span = ui::detail::bridge_probe(pc, R, C, 2); CHECK(span.status == ui::detail::BridgeStatus::Ok && span.span == W); ui::detail::bridge_lay(pc, span, /*causeway=*/0); Framebuffer causeway(900, 500); const ScreenPos centred = origin_centering_tile(R, C + W / 2, L + 1, 2, 450, 270); renderer.render(pc, causeway, Camera{centred.x, centred.y}); City imported = pc; imported.xbld.at(R, C) = xbld::kNone; imported.xbld.at(R, C + W - 1) = xbld::kNone; Framebuffer imported_causeway(900, 500); renderer.render(imported, imported_causeway, Camera{centred.x, centred.y}); long causeway_diff = 0; for (int y = 0; y < causeway.height(); ++y) for (int x = 0; x < causeway.width(); ++x) { const Rgba stored = causeway.at(x, y), inferred = imported_causeway.at(x, y); if (stored.r != inferred.r || stored.g != inferred.g || stored.b != inferred.b) ++causeway_diff; } CHECK(causeway_diff == 0); std::printf("city_render: power causeway stored-vs-inferred ramp diff=%ld px\n", causeway_diff); causeway.write_bmp("build/power_causeway.bmp"); }
// ---- Map skirt: the south/east edge draws a cliff/water-edge wall below the surface. ---- CHECK(a.bank.get(1269) != nullptr && a.bank.get(1284) != nullptr); { // An edge tile (row 127) raised above sea level must paint wall pixels strictly below its surface. City sc; CHECK(io::load_sc2(cityPath, sc).ok); const int ec = 64; sc.altm.at(127, ec) = 12; // a tall south-edge tile Framebuffer s(4200, 2600); renderer.render(sc, s, cam); const ScreenPos surf = tile_to_screen(127, ec, 12, 2, cam.x, cam.y); long wallPx = 0; for (int y = surf.y + 4; y < surf.y + 120 && y < s.height(); ++y) for (int x = surf.x - 14; x <= surf.x + 14 && x < s.width(); ++x) if (x >= 0 && y >= 0) { const Rgba p = s.at(x, y); if (!(p.r == kBackground.r && p.g == kBackground.g && p.b == kBackground.b)) ++wallPx; } std::printf("city_render: skirt wall drew %ld px below the edge\n", wallPx); CHECK(wallPx > 100); // a solid descending wall, not bare background }
// ---- Sub-tile glide: the renderer offsets a Thing's sprite by its sub-pixel position // (xsub/ysub @ +6/+7) so it slides smoothly between tiles. Proof it reaches the screen: a half-tile // sub-pixel step must move the sprite HALF as far as a whole tile step. The OLD renderer ignored // xsub and drew at the tile centre, so the sub-pixel render would be identical (shift 0) — the // teleport that read as "too fast / spazz". Measure the plane sprite's screen-x centroid. ---- { auto planeCentroidX = [&](int tileX, int xsub) -> double { City pc; if (!io::load_sc2(cityPath, pc).ok) return -1; Framebuffer base(4200, 2600); renderer.render(pc, base, cam); // baseline: no Thing pc.xthg[1 * 12 + 0] = 1; // airplane, pc.xthg[1 * 12 + 1] = 2; // facing E, pc.xthg[1 * 12 + 3] = std::uint8_t(tileX); pc.xthg[1 * 12 + 4] = 64; pc.xthg[1 * 12 + 6] = std::uint8_t(xsub); pc.xthg[1 * 12 + 7] = 8; Framebuffer pf(4200, 2600); renderer.render(pc, pf, cam); double sx = 0; long n = 0; for (int y = 0; y < pf.height(); ++y) for (int x = 0; x < pf.width(); ++x) { const Rgba p = pf.at(x, y), q = base.at(x, y); if (p.r != q.r || p.g != q.g || p.b != q.b) { sx += x; ++n; } } CHECK(n > 0); // the plane sprite composited at all return n ? sx / double(n) : -1; }; const double cx0 = planeCentroidX(64, 8); // rest pose (xsub 8 = tile centre) const double cxHalf = planeCentroidX(64, 16); // +half a tile of sub-pixel (xsub 16), same tile const double cxTile = planeCentroidX(65, 8); // +one whole tile east const double subShift = cxHalf - cx0; const double tileShift = cxTile - cx0; std::printf("city_render: plane glide subPixelShift=%.1f tileShift=%.1f (sub ≈ ½ tile)\n", subShift, tileShift); CHECK(subShift > 2.0); // the sub-pixel offset DID move the sprite (old code: 0) CHECK(tileShift > subShift + 2.0); // a whole tile moves further than half const double err = subShift - tileShift / 2.0; CHECK((err < 0 ? -err : err) < 3.0); // …and the half-tile step is ~half a tile — correct scale }
// ---- Layering: a ship is a SURFACE object — a deck/feature over its tile must OCCLUDE it (the ship // sails UNDER the bridge), so it's drawn IN the per-tile back-to-front pass (after the tile's // ground, BEFORE its feature), not in a top Things pass. (User: "ships appear over bridges".) A // same-tile feature (here a rail span — a stand-in deck that's known to render) must hide part of // the ship; the OLD top-pass renderer drew the ship OVER it, so this diff would be 0. ---- { const int tr = 64, tc = 64; auto setup = [&](City& sc, bool ship, bool deck) { CHECK(io::load_sc2(cityPath, sc).ok); for (int r = tr - 4; r <= tr + 4; ++r) // flat, empty, equal-height surroundings so nothing for (int cc = tc - 4; cc <= tc + 4; ++cc) { // nearer occludes the test tile sc.xter.at(r, cc) = 0; sc.xbld.at(r, cc) = 0; sc.xbit.at(r, cc) &= ~0x04; sc.xtxt.at(r, cc) = 0; sc.altm.at(r, cc) = 4; } if (deck) { sc.xbld.at(tr, tc) = 0x70; // a feature/deck over the tile (drawn after the ship) sc.xzon.at(tr, tc) = 0xF0; // 1×1 corner bits — developed tiles draw at their anchor bit } if (ship) { sc.xthg[1 * 12 + 0] = 3; // a cargo ship on the same tile, sailing under it sc.xthg[1 * 12 + 3] = tr; sc.xthg[1 * 12 + 4] = tc; sc.xthg[1 * 12 + 6] = 8; sc.xthg[1 * 12 + 7] = 8; } }; auto diff = [&](Framebuffer& a, 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; }; City c; Framebuffer base(4200, 2600), deckOnly(4200, 2600), withShip(4200, 2600); setup(c, false, false); renderer.render(c, base, cam); // open water setup(c, true, false); renderer.render(c, withShip, cam); const long shipOpen = diff(withShip, base); setup(c, false, true); renderer.render(c, deckOnly, cam); const long deckPx = diff(deckOnly, base); setup(c, true, true); renderer.render(c, withShip, cam); const long shipUnder = diff(withShip, deckOnly); std::printf("city_render: ship layering shipOpen=%ld deckPx=%ld shipUnderDeck=%ld\n", shipOpen, deckPx, shipUnder); CHECK(shipOpen > 50); // the ship clearly draws in the open, CHECK(deckPx > 20); // the deck clearly draws, CHECK(shipUnder < shipOpen); // …and the deck OCCLUDES part of the ship — it's underneath }
// ---- Ship UNDER a highway/bridge span stays VISIBLE (faithful tile order: the Thing overlay draws // after the tile's infra the tile draw exits). The own-tile thin span occludes only a little; the ship // is NOT hidden. (An earlier build HID the ship under any span + redrew far spans over it — that made // it vanish under bridges/power lines and garbled the deck; user-reported. Both removed.) ---- { const int tr = 64, tc = 64; auto setup = [&](City& sc, bool ship, bool span) { CHECK(io::load_sc2(cityPath, sc).ok); for (auto& v : sc.xthg) v = 0; for (int r = tr - 4; r <= tr + 2; ++r) // a clean patch of flat deep water (level 4) for (int cc = tc - 4; cc <= tc + 2; ++cc) { sc.xter.at(r, cc) = 0x10; sc.xbit.at(r, cc) |= 0x04; sc.xbld.at(r, cc) = 0; sc.xtxt.at(r, cc) = 0; sc.altm.at(r, cc) = (4 << 5) | 4; } if (span) for (int r = tr - 2; r <= tr; ++r) // a 1×1 highway span (0x49) over the water, covering the for (int cc = tc - 2; cc <= tc; ++cc) sc.xbld.at(r, cc) = 0x49; // ship's tile + its up-screen overlap if (ship) { sc.xthg[1 * 12 + 0] = 3; sc.xthg[1 * 12 + 3] = tr; sc.xthg[1 * 12 + 4] = tc; sc.xthg[1 * 12 + 6] = 8; sc.xthg[1 * 12 + 7] = 8; } }; auto diff = [&](Framebuffer& a, 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; }; City c; Framebuffer base(4200, 2600), A(4200, 2600), B(4200, 2600); setup(c, false, false); renderer.render(c, base, cam); setup(c, true, false); renderer.render(c, A, cam); const long shipOpen = diff(A, base); // ship alone setup(c, false, true); renderer.render(c, A, cam); const long spanPx = diff(A, base); // span alone (A := span) setup(c, true, true); renderer.render(c, B, cam); const long shipUnder = diff(B, A); // ship visible WITH the span std::printf("city_render: ship-under-span shipOpen=%ld spanPx=%ld shipUnderSpan=%ld\n", shipOpen, spanPx, shipUnder); CHECK(shipOpen > 50); // the ship draws, CHECK(spanPx > 50); // the highway span draws over the water, CHECK(shipUnder > shipOpen / 2); // …and the ship stays VISIBLE under it (NOT hidden — the fix) }
// ---- Aircraft float + shadow: a plane with altitude (frame>0) draws LIFTED above its // tile with a darkened shadow on the ground below — so its drawn region spans a tall vertical // range, unlike a grounded one. (User: "airplanes/helicopters cast shadows on terrain".) ---- { auto planeSpanY = [&](int frame) -> int { City pc; if (!io::load_sc2(cityPath, pc).ok) return 0; for (auto& v : pc.xthg) v = 0; // drop the save's in-flight Things so only our plane is measured for (int r = 62; r <= 66; ++r) // a patch of open ground so the shadow shows (XBLD<0x70) for (int cc = 62; cc <= 66; ++cc) { pc.xter.at(r, cc) = 0; pc.xbld.at(r, cc) = 0; pc.xbit.at(r, cc) &= ~0x04; pc.altm.at(r, cc) = 4; } Framebuffer base(4200, 2600); renderer.render(pc, base, cam); pc.xthg[1 * 12 + 0] = 1; pc.xthg[1 * 12 + 1] = 2; // a plane facing E at (64,64), pc.xthg[1 * 12 + 3] = 64; pc.xthg[1 * 12 + 4] = 64; pc.xthg[1 * 12 + 5] = std::uint8_t(frame); // …at altitude `frame` pc.xthg[1 * 12 + 6] = 8; pc.xthg[1 * 12 + 7] = 8; Framebuffer pf(4200, 2600); renderer.render(pc, pf, cam); int minY = 1 << 30, maxY = -1; for (int y = 0; y < pf.height(); ++y) for (int x = 0; x < pf.width(); ++x) { const Rgba p = pf.at(x, y), q = base.at(x, y); if (p.r != q.r || p.g != q.g || p.b != q.b) { if (y < minY) minY = y; if (y > maxY) maxY = y; } } return maxY < 0 ? 0 : maxY - minY; }; const int grounded = planeSpanY(0); // on the ground: no float, shadow hidden under the sprite const int flying = planeSpanY(12); // high: lifted ~96 px with a shadow left on the ground std::printf("city_render: aircraft float grounded ySpan=%d flying ySpan=%d\n", grounded, flying); CHECK(grounded > 0); // the plane drew, CHECK(flying > grounded + 40); // …and altitude stretches the drawn region tall (float + ground shadow) }
// ---- Effect / Thing / decal OCCLUSION (THE user-reported fix): fire, an explosion, and a bulldoze // "poof" behind a NEARER (foreground) building are now OCCLUDED by it. The original draws all three via // the per-tile overlay (the LAST op of every tile draw), so a closer building // drawn in a later diagonal hides them. Our OLD Pass 3/Pass 4 drew them after the WHOLE map, so they // floated OVER the foreground (the bug). Here: render each behind a wall, vs in the open; the wall // must hide some of it (fireWalled < fireOpen). With the old top-pass the two would be EQUAL. ---- { const int P = 64; auto diff = [&](Framebuffer& x, Framebuffer& y) { long n = 0; for (int yy = 0; yy < x.height(); ++yy) for (int xx = 0; xx < x.width(); ++xx) { const Rgba p = x.at(xx, yy), q = y.at(xx, yy); if (p.r != q.r || p.g != q.g || p.b != q.b) ++n; } return n; }; auto patch = [&](City& sc) { // a flat, empty, equal-height clearing around T=(P,P) CHECK(io::load_sc2(cityPath, sc).ok); for (auto& v : sc.xthg) v = 0; for (int r = P - 2; r <= P + 6; ++r) for (int c = P - 2; c <= P + 6; ++c) { sc.xter.at(r, c) = 0; sc.xbld.at(r, c) = 0; sc.xbit.at(r, c) &= ~0x04; sc.xtxt.at(r, c) = 0; sc.altm.at(r, c) = 4; } }; auto wall = [&](City& sc) { // a TALL building wall on the NEARER diagonal, screen-over T // 0x92 is a 78-px-tall 1×1 high-rise (vs 0x70's 18 px) — tall enough to bridge the 16-px-per-diagonal // screen gap and cover the fire/explosion/poof on T behind it. (A short building wouldn't occlude.) for (int r = P + 1; r <= P + 2; ++r) for (int c = P - 1; c <= P + 2; ++c) sc.xbld.at(r, c) = 0x92; }; City c; Framebuffer openBase(4200, 2600), wallBase(4200, 2600), A(4200, 2600); patch(c); renderer.render(c, openBase, cam); // clearing, nothing on T patch(c); wall(c); renderer.render(c, wallBase, cam); // clearing + the foreground wall
// (a) FIRE (XTXT 0xFF) on a building at T. patch(c); c.xbld.at(P, P) = 0x70; c.xtxt.at(P, P) = 0xFF; renderer.render(c, A, cam); const long fireOpen = diff(A, openBase); patch(c); wall(c); c.xbld.at(P, P) = 0x70; c.xtxt.at(P, P) = 0xFF; renderer.render(c, A, cam); const long fireWalled = diff(A, wallBase); // (b) EXPLOSION Thing (XTHG type 6) on T. patch(c); c.xthg[1 * 12 + 0] = 6; c.xthg[1 * 12 + 3] = P; c.xthg[1 * 12 + 4] = P; c.xthg[1 * 12 + 6] = 8; c.xthg[1 * 12 + 7] = 8; renderer.render(c, A, cam); const long explOpen = diff(A, openBase); patch(c); wall(c); c.xthg[1 * 12 + 0] = 6; c.xthg[1 * 12 + 3] = P; c.xthg[1 * 12 + 4] = P; c.xthg[1 * 12 + 6] = 8; c.xthg[1 * 12 + 7] = 8; renderer.render(c, A, cam); const long explWalled = diff(A, wallBase); // (c) A bulldoze "poof" DECAL on T (fed through render() — the depth-aware path the app now uses). std::vector<Decal> decal{{P, P, CityRenderer::debris_sprite_id(1), -4}}; patch(c); renderer.render(c, A, cam, 0, 0, 2, {}, decal); const long poofOpen = diff(A, openBase); patch(c); wall(c); renderer.render(c, A, cam, 0, 0, 2, {}, decal); const long poofWalled = diff(A, wallBase);
std::printf("city_render: occlusion fire %ld→%ld expl %ld→%ld poof %ld→%ld (open→behind wall)\n", fireOpen, fireWalled, explOpen, explWalled, poofOpen, poofWalled); CHECK(fireOpen > 30); CHECK(fireWalled < fireOpen); // the wall hides some of the fire, CHECK(explOpen > 30); CHECK(explWalled < explOpen); // …some of the explosion, CHECK(poofOpen > 30); CHECK(poofWalled < poofOpen); // …and some of the bulldoze poof (all were on-top before) }
// ---- "No power" warning badge (sprite 386, the flashing lightning bolt). The original draws it as the last // step of every tile draw for a tile that is CONDUCTIVE but UNPOWERED — // (XBIT & 0xC0) == 0x80 — centred on the feature and lifted off the tile surface. It is the ONLY // status badge in SC2K Win95 (there is no water / road indicator). Verify: it draws when the tile is // unpowered, NOT when powered, sits over the building's top-centre, and the env A/B gate hides it. ---- { const int P = 64; CHECK(a.bank.get(1386) != nullptr); // the bolt sprite is in the archive // The bolt is coloured with palette index 0xC3, which lives in the traffic-animation band (0xAB-0xDB) // and so flashes for free under the existing traffic palette cycle (group 0xC3-0xC6). Prove the art uses it. const Sprite* bolt = a.bank.get(1386); bool boltUsesAnimIdx = false; if (bolt) for (std::size_t i = 0; i < bolt->index.size(); ++i) if (bolt->mask[i] && bolt->index[i] >= 0xAB && bolt->index[i] <= 0xDB) { boltUsesAnimIdx = true; break; } CHECK(boltUsesAnimIdx); // the bolt rides the traffic cycle → it pulses auto diff = [&](Framebuffer& x, Framebuffer& y) { long n = 0; for (int yy = 0; yy < x.height(); ++yy) for (int xx = 0; xx < x.width(); ++xx) { const Rgba p = x.at(xx, yy), q = y.at(xx, yy); if (p.r != q.r || p.g != q.g || p.b != q.b) ++n; } return n; }; auto setup = [&](City& sc, std::uint8_t xbit) { // a flat clearing with one 1×1 building at T CHECK(io::load_sc2(cityPath, sc).ok); for (auto& v : sc.xthg) v = 0; for (int r = P - 2; r <= P + 4; ++r) for (int c = P - 2; c <= P + 4; ++c) { sc.xter.at(r, c) = 0; sc.xbld.at(r, c) = 0; sc.xbit.at(r, c) = 0; sc.xtxt.at(r, c) = 0; sc.altm.at(r, c) = 4; } sc.xbld.at(P, P) = 0x70; // a developed building, sc.xzon.at(P, P) = 0xF0; // its 1×1 corner bits (the draw anchor), sc.xbit.at(P, P) = xbit; // and the given power flags }; City c; Framebuffer powered(4200, 2600), unpowered(4200, 2600); setup(c, 0xC0); renderer.render(c, powered, cam); // conductive AND powered → no badge setup(c, 0x80); renderer.render(c, unpowered, cam); // conductive, NOT powered → badge const long badgePx = diff(unpowered, powered);
// The badge's screen position: centred on the building, just above the tile surface. const Sprite* feat = a.bank.get(1000 + 0x70); CHECK(feat != nullptr); const ScreenPos surf = tile_to_screen(P, P, 4, 2, cam.x, cam.y); // (a1, v36) at this tile's altitude const int cx = surf.x + (feat ? feat->width / 2 : 16); // building horizontal centre long inBox = 0, total = 0; double sx = 0, sy = 0; for (int y = 0; y < unpowered.height(); ++y) for (int x = 0; x < unpowered.width(); ++x) { const Rgba p = unpowered.at(x, y), q = powered.at(x, y); if (p.r == q.r && p.g == q.g && p.b == q.b) continue; ++total; sx += x; sy += y; if (x >= cx - 24 && x <= cx + 24 && y >= surf.y - 24 && y <= surf.y + 8) ++inBox; } const double cenX = total ? sx / total : 0, cenY = total ? sy / total : 0; std::printf("city_render: power badge px=%ld centroid=(%.0f,%.0f) expect≈(%d,%d) inBox=%ld\n", badgePx, cenX, cenY, cx, surf.y, inBox); CHECK(badgePx > 8); // the bolt clearly drew (≈20 opaque px) CHECK(inBox == total); // …and EVERY badge pixel sits over the building top-centre }
// ---- On-map SIGN occlusion (THE user-reported layering fix): a sign label drawn behind a NEARER // (foreground) building is now OCCLUDED by it. The original draws signs as the LAST op of // every DrawTile — so a closer building drawn in a later diagonal hides the post/plaque behind it. // Our OLD code drew every sign in a final full-screen pass, floating them OVER the foreground (the // bug). render() now invokes the app's sign hook at each tile's z-order moment; here a tall wall in // front must hide some of the sign (signWalled < signOpen). With the old top-pass they'd be EQUAL. ---- { const int P = 64; City c; // The sign hook the app passes to render() — minus the font (we draw a fixed-width plaque/post whose // occlusion we measure). Reads the sign index off the city's XTXT, projects the tile, and lays out the // plaque + post through the same presentation helpers as the app — exactly the // geometry the app uses, so this locks the real draw path's depth ordering. SignHook signHook = [&](Framebuffer& f, int row, int col) { const int idx = c.xtxt.at(row, col); if (idx < 1 || idx > 50) return; const ScreenPos p = tile_to_screen(row, col, renderer.tile_altitude(c, row, col), 2, cam.x, cam.y); const SignLayout s = sign_layout(p, 2, /*textW=*/40, /*fontH=*/8); draw_sign_plaque(f, s.plaqueX, s.plaqueY, s.plaqueW, s.plaqueH); draw_sign_post(f, s.postX, s.postY, s.postW, s.postH); }; auto diff = [&](Framebuffer& x, Framebuffer& y) { long n = 0; for (int yy = 0; yy < x.height(); ++yy) for (int xx = 0; xx < x.width(); ++xx) { const Rgba p = x.at(xx, yy), q = y.at(xx, yy); if (p.r != q.r || p.g != q.g || p.b != q.b) ++n; } return n; }; auto patch = [&](City& sc) { // a flat, empty clearing around T=(P,P) CHECK(io::load_sc2(cityPath, sc).ok); for (auto& v : sc.xthg) v = 0; for (int r = P - 2; r <= P + 6; ++r) for (int cc = P - 2; cc <= P + 6; ++cc) { sc.xter.at(r, cc) = 0; sc.xbld.at(r, cc) = 0; sc.xbit.at(r, cc) &= ~0x04; sc.xtxt.at(r, cc) = 0; sc.altm.at(r, cc) = 4; } }; auto wall = [&](City& sc) { // a wall of TALL (0x92, ~78 px) high-rises on the for (int r = P + 1; r <= P + 3; ++r) // nearer diagonals, screen-over the sign on T for (int cc = P - 2; cc <= P + 3; ++cc) sc.xbld.at(r, cc) = 0x92; }; Framebuffer openBase(4200, 2600), wallBase(4200, 2600), signOpen(4200, 2600), signWalled(4200, 2600); patch(c); renderer.render(c, openBase, cam, 0, 0, 2, {}, {}, signHook); // clearing, no sign patch(c); wall(c); renderer.render(c, wallBase, cam, 0, 0, 2, {}, {}, signHook); // clearing + wall patch(c); c.xtxt.at(P, P) = 1; renderer.render(c, signOpen, cam, 0, 0, 2, {}, {}, signHook); // sign in the open patch(c); wall(c); c.xtxt.at(P, P) = 1; renderer.render(c, signWalled, cam, 0, 0, 2, {}, {}, signHook); // sign behind the wall const long signOpenPx = diff(signOpen, openBase); const long signWalledPx = diff(signWalled, wallBase); std::printf("city_render: sign occlusion open=%ld behind wall=%ld\n", signOpenPx, signWalledPx); CHECK(signOpenPx > 100); // the plaque + post clearly drew, CHECK(signWalledPx < signOpenPx); // …and the foreground wall hid some of it (was EQUAL before)
// Gating: with the Signs layer toggled OFF (ViewToggles::signs=false) the hook is never called, so // placing a sign changes nothing. (Compared against a signs-OFF baseline — the city's own pre-existing // signs would otherwise show in the signs-ON render and swamp the diff.) ViewToggles noSigns; noSigns.signs = false; Framebuffer offNoSign(4200, 2600), offSign(4200, 2600); patch(c); renderer.render(c, offNoSign, cam, 0, 0, 2, noSigns, {}, signHook); patch(c); c.xtxt.at(P, P) = 1; renderer.render(c, offSign, cam, 0, 0, 2, noSigns, {}, signHook); std::printf("city_render: sign toggle-off drew=%ld (expect 0)\n", diff(offSign, offNoSign)); CHECK(diff(offSign, offNoSign) == 0); // Signs off → placing one draws nothing
// House-style presentation: clipped outer corners, blue enamel shell, pale inset face, // and a cylindrical aluminium post. Draw one in isolation and probe stable regions numerically. Framebuffer plaque(60, 50); plaque.clear({0, 0, 0, 0}); draw_sign_plaque(plaque, 5, 5, 40, 16); draw_sign_post(plaque, 23, 21, 4, 20); std::printf("city_render: sign house style shell=(%d) face=(%d) post=(%d)\n", plaque.at(10, 5).b, plaque.at(25, 13).r, plaque.at(24, 30).r); CHECK(plaque.at(5, 5).a == 0); // outer corner is clipped CHECK(plaque.at(10, 5).b == kSignShellLight.b); // blue painted top edge CHECK(plaque.at(6, 13).b == kSignShell.b); // shell remains two pixels thick here CHECK(plaque.at(7, 7).b == kSignShell.b); // rounded inset leaves its bounding corner blue CHECK(plaque.at(8, 7).r == kSignFace.r); // adjacent top pixel begins the pale curve CHECK(plaque.at(7, 13).r == kSignFace.r); // pale inset begins after the shell CHECK(plaque.at(25, 13).r == kSignFace.r); // pale inset face CHECK(plaque.at(25, 20).b == kSignShellShadow.b); // dark lower shell edge CHECK(plaque.at(23, 30).r == kSignPostProfile[0].r); // post's dark left edge CHECK(plaque.at(24, 30).r == kSignPostProfile[2].r); // aluminium highlight CHECK(plaque.at(25, 30).r == kSignPostProfile[4].r); // aluminium roll-off CHECK(plaque.at(26, 30).r == kSignPostProfile[7].r); // post's dark right edge
// Viewable crops (eyeballing only — the asserts above are the test): the house-style sign in the open, // and the same sign occluded behind the foreground wall. const ScreenPos at = tile_to_screen(P, P, 4, 2, cam.x, cam.y); auto crop = [&](Framebuffer& src, const char* path) { Framebuffer cr(220, 200); for (int y = 0; y < cr.height(); ++y) for (int x = 0; x < cr.width(); ++x) { const int sx = at.x - 110 + x, sy = at.y - 150 + y; if (sx >= 0 && sy >= 0 && sx < src.width() && sy < src.height()) cr.set(x, y, src.at(sx, sy)); } cr.write_bmp(path); }; crop(signOpen, "build/sign_open.bmp"); crop(signWalled, "build/sign_occluded.bmp"); }
// ---- PARTIAL footprints draw NO building (the corner-bit anchor gate). Real saves carry // multi-tile-code FRAGMENTS — growth churn overwrites part of a footprint (FOURCITI ships a // lone 3×3 Large Factory tile at (93,125)) — and the original's renderer only ever draws the // sprite at the tile whose XZON corner bit matches the view mask (word_4DC4C8), so a fragment // renders no building at all. The old geometric claim invented an anchor and drew a phantom, // mis-sorted sprite ("freakish layering", unselectable tiles). The port lays terrain under // every un-anchored tile (deliberate deviation: the original leaves a background hole). // Numeric check, all 4 rotations: a COMPLETE 3×3 draws exactly once at its footprint; a LONE // fragment tile contributes zero pixels. { auto mk = [&](bool complete, bool fragment) { City c; // flat empty ground, alt 0 if (complete) { for (int r = 60; r < 63; ++r) for (int cc = 60; cc < 63; ++cc) { c.xbld.at(r, cc) = 0xBD; // Large Factory (3×3) c.xzon.at(r, cc) = 0x06; // dense-industrial nibble } c.xzon.at(60, 60) |= 0x10; // rotation-0 corner bits c.xzon.at(62, 60) |= 0x20; c.xzon.at(62, 62) |= 0x40; c.xzon.at(60, 62) |= 0x80; } if (fragment) { c.xbld.at(70, 70) = 0xBD; // a lone footprint fragment — c.xzon.at(70, 70) = 0x06; // zone nibble, NO corner bits } return c; }; auto diff = [&](const Framebuffer& x, const Framebuffer& y) { long n = 0; for (int yy = 0; yy < x.height(); ++yy) for (int xx = 0; xx < x.width(); ++xx) { const Rgba p = x.at(xx, yy), q = y.at(xx, yy); if (p.r != q.r || p.g != q.g || p.b != q.b) ++n; } return n; }; for (int rot = 0; rot < 4; ++rot) { Framebuffer base(4200, 2600), withB(4200, 2600), withFrag(4200, 2600); renderer.render(rotate_city(mk(false, false), rot), base, cam, rot); renderer.render(rotate_city(mk(true, false), rot), withB, cam, rot); renderer.render(rotate_city(mk(true, true), rot), withFrag, cam, rot); const long bldPx = diff(withB, base); const long fragPx = diff(withFrag, withB); std::printf("city_render: partial-footprint rot=%d building px=%ld fragment px=%ld\n", rot, bldPx, fragPx); CHECK(bldPx > 500); // the complete 3×3 clearly draws… CHECK(fragPx == 0); // …the lone fragment draws NOTHING } }
// Drop a snapshot for eyeballing (not the test's basis — the asserts above are). fb.write_bmp("build/city_render.bmp");
if (failures == 0) { std::printf("city_render: all checks passed\n"); return 0; } std::printf("city_render: %d failure(s)\n", failures); return 1;}