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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071#include "sc2k/ui/simulation_speed.hpp"
#include <cstdio>
#include "test_harness.hpp"
int main() { using sc2k::ui::SimulationSpeed; using sc2k::ui::effective_simulation_speed; using sc2k::ui::reset_simulation_speed_for_document; using sc2k::ui::simulation_speed_after_ui_pause_transition; using sc2k::ui::select_simulation_speed; using sc2k::ui::toggled_simulation_speed;
SimulationSpeed current = SimulationSpeed::Pause; SimulationSpeed lastRunning = SimulationSpeed::Turtle;
// Within one city, pause is temporary and Play restores the player's chosen pace. select_simulation_speed(current, lastRunning, SimulationSpeed::Swallow); CHECK(current == SimulationSpeed::Swallow); CHECK(lastRunning == SimulationSpeed::Swallow); select_simulation_speed(current, lastRunning, SimulationSpeed::Pause); CHECK(current == SimulationSpeed::Pause); CHECK(lastRunning == SimulationSpeed::Swallow); select_simulation_speed(current, lastRunning, toggled_simulation_speed(current, lastRunning)); CHECK(current == SimulationSpeed::Swallow);
// A new, loaded, imported, or command-line-opened document gets a fresh safety boundary. reset_simulation_speed_for_document(current, lastRunning); CHECK(current == SimulationSpeed::Pause); CHECK(lastRunning == SimulationSpeed::Turtle); select_simulation_speed(current, lastRunning, toggled_simulation_speed(current, lastRunning)); CHECK(current == SimulationSpeed::Turtle); CHECK(lastRunning == SimulationSpeed::Turtle);
// A later document boundary must also discard a pace selected in the current city. select_simulation_speed(current, lastRunning, SimulationSpeed::Cheetah); reset_simulation_speed_for_document(current, lastRunning); CHECK(current == SimulationSpeed::Pause); CHECK(lastRunning == SimulationSpeed::Turtle);
// Temporary UI suspension changes only the effective pace. Nested owners therefore cannot // overwrite or prematurely restore the player's selected speed. select_simulation_speed(current, lastRunning, SimulationSpeed::Swallow); CHECK(effective_simulation_speed(current, false) == SimulationSpeed::Swallow); CHECK(effective_simulation_speed(current, true) == SimulationSpeed::Pause); CHECK(current == SimulationSpeed::Swallow); CHECK(lastRunning == SimulationSpeed::Swallow); CHECK(effective_simulation_speed(current, true) == SimulationSpeed::Pause); // child closes; parent remains CHECK(effective_simulation_speed(current, false) == SimulationSpeed::Swallow); // final owner closes
select_simulation_speed(current, lastRunning, SimulationSpeed::Pause); CHECK(effective_simulation_speed(current, true) == SimulationSpeed::Pause); CHECK(effective_simulation_speed(current, false) == SimulationSpeed::Pause); // already paused stays paused
// Releasing the final temporary pause owner deliberately tames the uncapped speed. Nested // transitions and every already-bounded selected pace remain unchanged. CHECK(simulation_speed_after_ui_pause_transition(SimulationSpeed::Swallow, true, true) == SimulationSpeed::Swallow); CHECK(simulation_speed_after_ui_pause_transition(SimulationSpeed::Swallow, true, false) == SimulationSpeed::Cheetah); CHECK(simulation_speed_after_ui_pause_transition(SimulationSpeed::Cheetah, true, false) == SimulationSpeed::Cheetah); CHECK(simulation_speed_after_ui_pause_transition(SimulationSpeed::Pause, true, false) == SimulationSpeed::Pause); CHECK(simulation_speed_after_ui_pause_transition(SimulationSpeed::Swallow, false, false) == SimulationSpeed::Swallow);
if (failures == 0) { std::printf("simulation_speed: document reset + UI suspension + bounded resume OK\n"); return 0; } std::printf("simulation_speed: %d failure(s)\n", failures); return 1;}