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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115// Highway render smoke test (Phase 5): the autotiler (sim/highway_autotile.hpp) lays the flat curve /// interchange pieces (0x65-0x69) as well as straights — confirm they actually RENDER (as 2×2 elevated decks// via the renderer's same-code NE-anchor claim pass) and aren't dropped or garbled. Numeric, per// feedback-verify-visuals-numerically: lay an L-bend + a 4-way on flat land and assert (a) the autotiler// produced the expected codes and (b) the rendered region gains real pixels over the bare-terrain baseline.// Also drops a viewable BMP crop in build/. Skips when the extracted Win95 art is absent.#include "sc2k/render/asset_loader.hpp"#include "sc2k/render/city_renderer.hpp"#include "sc2k/sim/highway_path.hpp"#include <cstdio>#include <fstream>#include <string>
using namespace sc2k;using namespace sc2k::render;
#include "test_harness.hpp"#include "test_paths.hpp"// Count pixels in the screen box (around a span of original tiles) whose colour DIFFERS between two renders —// i.e. what the highway changed (the decks/straights overdraw the flat terrain, so a coverage count wouldn't// move; a difference count does).static long changed_in_box(const Framebuffer& a, const Framebuffer& b, int loR, int loC, int hiR, int hiC, const Camera& cam) { int minX = a.width(), maxX = 0, minY = a.height(), maxY = 0; for (int r : {loR, hiR}) for (int c : {loC, hiC}) { const ScreenPos s = tile_to_screen(r, c, 0, 2, cam.x, cam.y); // zoom 2 = the renderer default minX = std::min(minX, s.x - 60); maxX = std::max(maxX, s.x + 60); minY = std::min(minY, s.y - 80); maxY = std::max(maxY, s.y + 30); } minX = std::max(0, minX); minY = std::max(0, minY); maxX = std::min(a.width(), maxX); maxY = std::min(a.height(), maxY); long n = 0; for (int y = minY; y < maxY; ++y) for (int x = minX; x < maxX; ++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;}
int main() { if (!have_render_assets()) { std::printf("highway_render: SKIP (no extracted assets — run extract_assets.py)\n"); return 0; } const Assets a = load_assets(); CityRenderer renderer(a.bank, a.palette);
// A flat, sea-level synthetic city. (1) a single DIAGONAL drag → a staircase of straights + curves at every // turn; (2) a 4-way interchange built from a centre block + its four neighbour blocks (highways meet by // adjacency, not by crossing — a new drag can't run over an existing highway tile, which is faithful). City city; sim::commit_highway_path(city, sim::solve_highway_path(city, 60, 60, 66, 66)); // diagonal staircase sim::place_highway_block(city, 50, 50, 2); // interchange centre sim::place_highway_block(city, 50, 48, 2); // W sim::place_highway_block(city, 50, 52, 2); // E sim::place_highway_block(city, 48, 50, 1); // N sim::place_highway_block(city, 52, 50, 1); // S
// (a) the autotiler produced curve / straight / interchange codes (not all plain 0x49). auto is_curve = [](int x) { return x >= 0x65 && x <= 0x68; }; int straights = 0, curves = 0, inters = 0; for (int r = 46; r <= 67; ++r) for (int c = 46; c <= 67; ++c) { const int x = city.xbld.at(r, c); if (x == 0x49 || x == 0x4A) ++straights; else if (is_curve(x)) ++curves; else if (x == 0x69) ++inters; } CHECK(straights > 0); // plain 2-lane runs CHECK(curves > 0); // staircase corners CHECK(inters > 0); // the 4-way junction (centre block) CHECK(city.xbld.at(50, 50) == 0x69); // the interchange centre specifically std::printf(" highway codes: straights=%d curves=%d interchanges=%d\n", straights, curves, inters);
// (b) render & compare to the bare-terrain baseline: the highway must change real pixels in its region. Framebuffer fb(4200, 2600); const Camera cam{2100, 420}; City bare; // identical empty terrain, no highway Framebuffer fb0(4200, 2600); renderer.render(bare, fb0, cam); renderer.render(city, fb, cam); const long changedStair = changed_in_box(fb0, fb, 60, 60, 66, 66, cam); const long changedInter = changed_in_box(fb0, fb, 48, 48, 52, 52, cam); std::printf(" changed px: staircase=%ld interchange=%ld\n", changedStair, changedInter); CHECK(changedStair > 2000); // the staircase decks overdraw the flat terrain CHECK(changedInter > 1000); // the interchange renders too
// viewable crop centred on the interchange for manual inspection. { const ScreenPos ctr = tile_to_screen(50, 50, 0, 2, cam.x, cam.y); Framebuffer crop(640, 480); for (int y = 0; y < crop.height(); ++y) for (int x = 0; x < crop.width(); ++x) { const int sx = ctr.x - 320 + x, sy = ctr.y - 240 + y; if (sx >= 0 && sy >= 0 && sx < fb.width() && sy < fb.height()) crop.set(x, y, fb.at(sx, sy)); } crop.write_bmp("build/highway_render.bmp"); }
if (failures == 0) std::printf("highway_render: ALL CHECKS PASSED\n"); else std::printf("highway_render: %d CHECK(S) FAILED\n", failures); return failures ? 1 : 0;}