MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / simulate

Function simulate

src/OpenLoco/src/CommandLine.cpp:544–604  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

542 }
543
544 static int simulate(const CommandLineOptions& options)
545 {
546 setCommandLineOptions(options);
547
548 if (!options.ticks)
549 {
550 Logging::error("Number of ticks to simulate not specified");
551 return EXIT_FAILURE;
552 }
553
554 auto inPath = fs::u8path(options.path);
555 auto outPath = fs::u8path(options.outputPath);
556 auto comparePath = fs::u8path(options.path2);
557
558 const auto timeStarted = std::chrono::high_resolution_clock::now();
559
560 try
561 {
562 OpenLoco::simulateGame(inPath, *options.ticks);
563 }
564 catch (...)
565 {
566 Logging::error("Unable to load and simulate {}", inPath.u8string());
567 return EXIT_FAILURE;
568 }
569
570 if (!options.path2.empty())
571 {
572 OpenLoco::GameSaveCompare::compareGameStates(comparePath);
573 }
574
575 const auto timeElapsed = std::chrono::high_resolution_clock::now() - timeStarted;
576
577 auto& gameState = getGameState();
578 Logging::info("--------------------------------");
579 Logging::info("- Simulate");
580 Logging::info("--------------------------------");
581 Logging::info("Input:");
582 Logging::info(" path: {}", inPath.u8string());
583 Logging::info(" ticks: {} ticks", *options.ticks);
584 Logging::info("Output:");
585 Logging::info(" scenario ticks: {}", gameState.scenarioTicks);
586 Logging::info(" rng: {{ {}, {} }}", gameState.rng.srand_0(), gameState.rng.srand_1());
587 Logging::info("Duration: {:%S} sec", timeElapsed);
588
589 if (!outPath.empty())
590 {
591 try
592 {
593 S5::exportGameStateToFile(outPath, S5::SaveFlags::none);
594 std::printf(" path: %s\n", outPath.u8string().c_str());
595 }
596 catch (...)
597 {
598 Logging::error("Unable to save game to {}", outPath.u8string());
599 return EXIT_FAILURE;
600 }
601 }

Callers 1

Calls 9

setCommandLineOptionsFunction · 0.85
errorFunction · 0.85
simulateGameFunction · 0.85
compareGameStatesFunction · 0.85
infoFunction · 0.85
exportGameStateToFileFunction · 0.85
srand_0Method · 0.80
srand_1Method · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected