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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213// Release utility identity: committed City bits, Simulation publication, minimap/live overlay, and legend.#include "sc2k/render/asset_loader.hpp"#include "sc2k/render/iso_projection.hpp"#include "sc2k/render/minimap.hpp"#include "sc2k/render/overlay_draw.hpp"#include "sc2k/render/rotate.hpp"#include "sc2k/sim/simulation.hpp"#include "sc2k/sim/utility_delivery_diagnostics.hpp"#include "sc2k/ui/utility_delivery_legend.hpp"
#include <cstdio>
#include "test_harness.hpp"#include "test_paths.hpp"
using namespace sc2k;
namespace {
City fixture() { City city{MapSize::Tiny}; city.xbld.at(1, 1) = xbld::kPowerFirst; city.xbit.at(1, 1) = xbit::kConductive | xbit::kPowered; city.xbld.at(2, 2) = xbld::kFirstDeveloped; city.xbit.at(2, 2) = xbit::kConductive | xbit::kPowered; city.xbld.at(3, 3) = xbld::kFirstDeveloped; city.xbit.at(3, 3) = xbit::kConductive; city.xbit.at(4, 4) = xbit::kConductive;
city.xund.at(5, 5) = xund::kPipeFirst; city.xbit.at(5, 5) = xbit::kPipe | xbit::kWatered; city.xbit.at(6, 6) = xbit::kPipe | xbit::kWatered; city.xbit.at(7, 7) = xbit::kPipe; city.xund.at(8, 8) = xund::kSubwaySilo; return city;}
void exact_states_and_geometry() { for (const MapSize size : {MapSize::Tiny, MapSize::Small, MapSize::Medium, MapSize::Large}) { City city{size}; const sim::UtilityDeliveryDiagnostics diagnostics = sim::utility_delivery_diagnostics(city); CHECK(diagnostics.ok()); CHECK(diagnostics.fullRows == static_cast<std::uint32_t>(city.dimension())); CHECK(diagnostics.buildings.size() == static_cast<std::size_t>(city.tile_count())); }
City city = fixture(); const sim::UtilityDeliveryDiagnostics diagnostics = sim::utility_delivery_diagnostics(city); CHECK(sim::utility_delivery_at(diagnostics, sim::UtilityDeliveryKind::Electricity, 1, 1) == sim::UtilityDeliveryTileState::Network); CHECK(sim::utility_delivery_at(diagnostics, sim::UtilityDeliveryKind::Electricity, 2, 2) == sim::UtilityDeliveryTileState::Supplied); CHECK(sim::utility_delivery_at(diagnostics, sim::UtilityDeliveryKind::Electricity, 3, 3) == sim::UtilityDeliveryTileState::Unmet); CHECK(sim::utility_delivery_at(diagnostics, sim::UtilityDeliveryKind::Electricity, 4, 4) == sim::UtilityDeliveryTileState::NoEffect); CHECK(sim::utility_delivery_at(diagnostics, sim::UtilityDeliveryKind::Water, 5, 5) == sim::UtilityDeliveryTileState::Network); CHECK(sim::utility_delivery_at(diagnostics, sim::UtilityDeliveryKind::Water, 6, 6) == sim::UtilityDeliveryTileState::Supplied); CHECK(sim::utility_delivery_at(diagnostics, sim::UtilityDeliveryKind::Water, 7, 7) == sim::UtilityDeliveryTileState::Unmet); CHECK(sim::utility_delivery_at(diagnostics, sim::UtilityDeliveryKind::Water, 8, 8) == sim::UtilityDeliveryTileState::NoEffect); CHECK(!sim::utility_delivery_at(diagnostics, sim::UtilityDeliveryKind::Water, 64, 0)); CHECK(!sim::utility_delivery_at(diagnostics, static_cast<sim::UtilityDeliveryKind>(99), 0, 0));
Simulation simulation(city); CHECK(simulation.utility_delivery_diagnostics() == diagnostics);
city.xund.cells.pop_back(); const sim::UtilityDeliveryDiagnostics invalid = sim::utility_delivery_diagnostics(city); CHECK(!invalid.ok()); CHECK(!sim::utility_delivery_at(invalid, sim::UtilityDeliveryKind::Water, 0, 0));}
void projection_is_exact_and_fixes_subway_pipe_confusion() { City city = fixture(); const sim::UtilityDeliveryDiagnostics diagnostics = sim::utility_delivery_diagnostics(city); const auto powerNetwork = render::utility_delivery_view_sample( diagnostics, sim::UtilityDeliveryKind::Electricity, 1, 1); const auto powerSupplied = render::utility_delivery_view_sample( diagnostics, sim::UtilityDeliveryKind::Electricity, 2, 2); const auto powerUnmet = render::utility_delivery_view_sample( diagnostics, sim::UtilityDeliveryKind::Electricity, 3, 3); CHECK(powerNetwork && powerNetwork->paletteIndex == 255); CHECK(powerSupplied && powerSupplied->paletteIndex == 50); CHECK(powerUnmet && powerUnmet->paletteIndex == 29);
CHECK(render::view_index(city, render::MapView::Power, 1, 1, nullptr, nullptr, nullptr, &diagnostics) == 255); CHECK(render::view_index(city, render::MapView::Power, 2, 2, nullptr, nullptr, nullptr, &diagnostics) == 50); CHECK(render::view_index(city, render::MapView::Power, 3, 3, nullptr, nullptr, nullptr, &diagnostics) == 29); CHECK(render::view_index(city, render::MapView::Water, 5, 5, nullptr, nullptr, nullptr, &diagnostics) == 255); CHECK(render::view_index(city, render::MapView::Water, 6, 6, nullptr, nullptr, nullptr, &diagnostics) == 50); CHECK(render::view_index(city, render::MapView::Water, 7, 7, nullptr, nullptr, nullptr, &diagnostics) == 29);
// The old numeric range treated subway-only codes as pipes. Both the exact diagnostic and the // compatibility fallback now use xund::is_pipe, so a subway silo remains ordinary terrain. const std::uint8_t siloBase = render::minimap_base_index( city.xbld.at(8, 8), city.xbit.at(8, 8), city.altm.at(8, 8)); CHECK(render::view_index(city, render::MapView::Water, 8, 8) == siloBase); CHECK(render::view_index(city, render::MapView::Water, 8, 8, nullptr, nullptr, nullptr, &diagnostics) == siloBase);
const render::Framebuffer minimap = render::render_minimap(city, render::MapView::Power, nullptr, nullptr, nullptr, nullptr, &diagnostics); CHECK(minimap.at(2, 2) == render::minimap_color(50));
constexpr int rotation = 1; constexpr int zoom = 0; constexpr int camX = 300; constexpr int camY = 100; int viewRow = 0; int viewColumn = 0; render::rotate_index_cw_n(city.dimension(), 2, 2, rotation, viewRow, viewColumn); const render::ScreenPos anchor = render::tile_to_screen( viewRow, viewColumn, 0, zoom, camX, camY); const render::Rgba background{7, 11, 13, 255}; render::Framebuffer software(900, 900); software.clear(background); render::draw_mapview_overlay(software, city, camX, camY, rotation, zoom, render::MapView::Power, 255, 1.f, nullptr, nullptr, nullptr, &diagnostics); render::Framebuffer gpuChrome(1800, 1800); gpuChrome.clear(background); render::draw_mapview_overlay(gpuChrome, city, camX, camY, rotation, zoom, render::MapView::Power, 255, 2.f, nullptr, nullptr, nullptr, &diagnostics); const render::Rgba expected = render::minimap_color(50); CHECK(software.at(anchor.x + 4, anchor.y + 2) == expected); CHECK(gpuChrome.at(2 * (anchor.x + 4), 2 * (anchor.y + 2)) == expected);}
void legend_covers_every_emitted_category() { City city = fixture(); const sim::UtilityDeliveryDiagnostics diagnostics = sim::utility_delivery_diagnostics(city); const auto hovered = render::utility_delivery_view_sample( diagnostics, sim::UtilityDeliveryKind::Water, 7, 7); const std::string fontPath = render::assets_dir() + "/fonts/NotoSans-Regular.ttf"; if (!exists(fontPath)) return; ui::Font font(fontPath, 15); render::Framebuffer frame(640, 240); const render::Rgba untouched{3, 5, 7, 255}; frame.clear(untouched); const ui::UtilityDeliveryLegendGeometry geometry = ui::draw_utility_delivery_legend(frame, font, sim::UtilityDeliveryKind::Water, &diagnostics, hovered, 20, 220); CHECK(geometry.width >= 260); CHECK(geometry.height > 3 * font.height()); CHECK(frame.at(0, 0) == untouched); const int top = 220 - geometry.height; const render::UtilityDeliveryViewLegend legend = render::utility_delivery_view_legend(); const std::uint8_t expectedIndices[3] = { legend.networkPaletteIndex, legend.suppliedPaletteIndex, legend.unmetPaletteIndex}; for (int segment = 0; segment < 3; ++segment) { const int sampleX = 20 + geometry.barX + (2 * segment + 1) * geometry.barWidth / 6; const int sampleY = top + geometry.barY + geometry.barHeight / 2; CHECK(frame.at(sampleX, sampleY) == render::minimap_color(expectedIndices[segment])); }}
} // namespace
int main() { exact_states_and_geometry(); projection_is_exact_and_fixes_subway_pipe_confusion(); legend_covers_every_emitted_category();
if (failures == 0) { std::puts("utility delivery diagnostics: all checks passed"); return 0; } std::printf("utility delivery diagnostics: %d failure(s)\n", failures); return 1;}