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// tests/test_terrain_projection.cpp — the temporary canonical-to-XTER/ALTM renderer compatibility path.#include "sc2k/terrain/legacy_projection.hpp"#include "sc2k/terrain/legacy_import.hpp"#include "sc2k/structure/legacy_import.hpp"
#include <algorithm>#include <cstdio>#include <vector>
#include "test_harness.hpp"
int main() { using namespace sc2k; using namespace sc2k::terrain;
std::vector<Height> heights(129 * 129, 4 * kHeightQuantum); heights[1 * 129 + 1] += kHeightQuantum; const auto model = Model::create({128, 128}, heights); CHECK(model.has_value());
City city; std::fill(city.xter.cells.begin(), city.xter.cells.end(), 0x0C); // projection must derive these from Model std::fill(city.altm.cells.begin(), city.altm.cells.end(), 1); city.xter.at(10, 10) = xter::kCube; city.xbld.at(10, 10) = xbld::kHighwaySlopeFirst; city.xter.at(20, 20) = 0x30; city.xbit.at(20, 20) |= xbit::kWater;
const LegacyProjectionReport report = project_to_legacy(*model, city); CHECK(report.ok()); CHECK(report.projected_tiles == City::kTiles); CHECK(report.preserved_constructed_supports == 1); CHECK(report.preserved_water_visuals == 1); CHECK(city.xter.at(0, 0) == static_cast<std::uint8_t>(Shape::BottomHigh)); CHECK(city.xter.at(10, 10) == xter::kCube); CHECK(city.xter.at(20, 20) == 0x30); CHECK((city.altm.at(80, 80) & 0x1F) == 4); CHECK(matches_legacy_projection(*model, city)); city.altm.at(80, 80) = 3; CHECK(!matches_legacy_projection(*model, city));
// Once STRC exists it is authoritative: a stale foundation in COMP disappears, while an extracted // foundation survives even if the compatibility terrain byte was lost. City structureSource = city; structureSource.altm.at(80, 80) = 4; structureSource.xter.at(10, 10) = xter::kFlat; structureSource.xter.at(30, 30) = xter::kCube; structureSource.xbld.at(30, 30) = xbld::kRailFirst; const auto structures = structure::import_legacy_structures(structureSource); CHECK(structures.has_value()); structureSource.xter.at(30, 30) = xter::kFlat; structureSource.xter.at(10, 10) = xter::kCube; // stale support absent from STRC CHECK(project_to_legacy(*model, structureSource, &*structures).ok()); CHECK(structureSource.xter.at(30, 30) == xter::kCube); CHECK(structureSource.xter.at(10, 10) != xter::kCube);
// Constructed ramps carry their presentation lift without changing canonical ground. std::vector<structure::Support> rampSupports(City::kTiles); rampSupports[50 * City::kDim + 50] = { structure::SupportKind::Ramp, xter::kSlopeCardFirst, 1, true}; const auto rampStructures = structure::Model::create({City::kDim, City::kDim}, rampSupports); CHECK(rampStructures.has_value()); City rampCity; CHECK(project_to_legacy(*model, rampCity, &*rampStructures).ok()); CHECK(rampCity.xter.at(50, 50) == xter::kSlopeCardFirst); CHECK((rampCity.altm.at(50, 50) & 0x1F) == 5); CHECK(matches_legacy_projection(*model, rampCity, &*rampStructures));
// Imported tile-local route grades are canonical terrain patches. Projection derives their saved // shape and elevation without a structural compatibility surface. City gradeCity; for (std::uint16_t& altitude : gradeCity.altm.cells) altitude = 4; gradeCity.xbld.at(60, 60) = xbld::kRoadFirst; gradeCity.xter.at(60, 60) = static_cast<std::uint8_t>(Shape::RightHigh); gradeCity.altm.at(60, 60) = 6; const LegacyImportResult gradeImport = import_legacy_terrain(gradeCity); CHECK(gradeImport.terrain.has_value()); const auto gradeStructures = structure::import_legacy_structures( gradeCity, gradeImport.terrain ? &*gradeImport.terrain : nullptr); CHECK(gradeStructures.has_value()); CHECK(!gradeStructures->support({60, 60})); CHECK(project_to_legacy(*gradeImport.terrain, gradeCity, &*gradeStructures).ok()); CHECK(gradeCity.xter.at(60, 60) == static_cast<std::uint8_t>(Shape::RightHigh)); CHECK((gradeCity.altm.at(60, 60) & 0x1F) == 6); CHECK(matches_legacy_projection(*gradeImport.terrain, gradeCity, &*gradeStructures));
// A cube scar above an underground route is not a structural foundation. Canonical projection repairs // the surface while leaving the pipe/subway layer intact, so legacy migration loses no connectivity. City undergroundScar = city; undergroundScar.xter.at(40, 40) = xter::kCube; undergroundScar.xbld.at(40, 40) = 0; undergroundScar.xund.at(40, 40) = 0x10; const auto scarStructures = structure::import_legacy_structures(undergroundScar); CHECK(scarStructures.has_value()); CHECK(!scarStructures->support({40, 40})); CHECK(project_to_legacy(*model, undergroundScar, &*scarStructures).ok()); CHECK(undergroundScar.xter.at(40, 40) != xter::kCube); CHECK(undergroundScar.xund.at(40, 40) == 0x10);
const auto tooHigh = Model::create({128, 128}, std::vector<Height>(129 * 129, 32 * kHeightQuantum)); CHECK(tooHigh.has_value()); CHECK(project_to_legacy(*tooHigh, city).error == LegacyProjectionError::HeightUnrepresentable);
const auto wrongSize = Model::create({2, 2}, std::vector<Height>(9, 0)); CHECK(wrongSize.has_value()); CHECK(project_to_legacy(*wrongSize, city).error == LegacyProjectionError::ExtentMismatch);
if (failures == 0) { std::printf("terrain projection: canonical ground with temporary support/water presentation\n"); return 0; } std::printf("terrain projection: %d failure(s)\n", failures); return 1;}