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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051// Pure test of Simulation::debug_snapshot() (SC2K_DEBUG only; the test build always defines it). Asserts// the snapshot mirrors the public sim/city getters, is idempotent, and is strictly read-only — it must// not advance the clock or the validated RNG (a debug HUD reading it can't perturb the simulation).#include "sc2k/sim/simulation.hpp"#include <cstdio>
using namespace sc2k;
#include "test_harness.hpp"
int main() { City c; c.set_funds(12345); c.set_demand(0, 100); c.set_demand(1, -50); c.set_demand(2, 200); Simulation sim(c);
// Snapshot mirrors the public getters. const DebugSnapshot s1 = sim.debug_snapshot(); CHECK(s1.funds == 12345); CHECK(s1.demand[0] == 100 && s1.demand[1] == -50 && s1.demand[2] == 200); CHECK(s1.clock == sim.clock()); CHECK(s1.month == sim.month() && s1.year == sim.year() && s1.season == sim.season()); CHECK(s1.tickPhase == ((sim.clock() % 25) + 25) % 25); CHECK(s1.coverageFireSum == 0 && s1.coveragePoliceSum == 0); // blank city: no stations
// Read-only + idempotent: taking it again is identical and advances nothing. const std::int32_t beforeClock = sim.clock(); const std::int32_t beforeFunds = c.funds(); const DebugSnapshot s2 = sim.debug_snapshot(); CHECK(s2.clock == s1.clock && s2.funds == s1.funds && s2.demand[2] == s1.demand[2]); CHECK(sim.clock() == beforeClock); // snapshot did not tick CHECK(c.funds() == beforeFunds); // snapshot did not mutate the city
// After real ticks, tickPhase tracks the master clock and the snapshot keeps up. sim.tick(); sim.tick(); sim.tick(); const DebugSnapshot s3 = sim.debug_snapshot(); CHECK(s3.clock == beforeClock + 3); CHECK(s3.tickPhase == sim.clock() % 25);
if (failures == 0) { std::printf("debug_snapshot: all checks passed\n"); return 0; } std::printf("debug_snapshot: %d failure(s)\n", failures); return 1;}