From 36f75f89a03c41842a7ffd5e84aeabae8f801c9e Mon Sep 17 00:00:00 2001 From: ZehMatt Date: Fri, 19 Jan 2018 08:26:28 +0100 Subject: [PATCH] Add "simulate" command. --- src/openrct2/cmdline/CommandLine.hpp | 1 + src/openrct2/cmdline/RootCommands.cpp | 2 +- src/openrct2/cmdline/SimulateCommands.cpp | 75 +++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/openrct2/cmdline/SimulateCommands.cpp diff --git a/src/openrct2/cmdline/CommandLine.hpp b/src/openrct2/cmdline/CommandLine.hpp index 322565678d..6d7797086e 100644 --- a/src/openrct2/cmdline/CommandLine.hpp +++ b/src/openrct2/cmdline/CommandLine.hpp @@ -117,6 +117,7 @@ namespace CommandLine extern const CommandLineCommand ScreenshotCommands[]; extern const CommandLineCommand SpriteCommands[]; extern const CommandLineCommand BenchGfxCommands[]; + extern const CommandLineCommand SimulateCommands[]; extern const CommandLineExample RootExamples[]; diff --git a/src/openrct2/cmdline/RootCommands.cpp b/src/openrct2/cmdline/RootCommands.cpp index 29d509b5fa..5b866ef2c8 100644 --- a/src/openrct2/cmdline/RootCommands.cpp +++ b/src/openrct2/cmdline/RootCommands.cpp @@ -138,7 +138,7 @@ const CommandLineCommand CommandLine::RootCommands[] DefineSubCommand("screenshot", CommandLine::ScreenshotCommands), DefineSubCommand("sprite", CommandLine::SpriteCommands ), DefineSubCommand("benchgfx", CommandLine::BenchGfxCommands ), - + DefineSubCommand("simulate", CommandLine::SimulateCommands ), CommandTableEnd }; diff --git a/src/openrct2/cmdline/SimulateCommands.cpp b/src/openrct2/cmdline/SimulateCommands.cpp new file mode 100644 index 0000000000..55eacedd3f --- /dev/null +++ b/src/openrct2/cmdline/SimulateCommands.cpp @@ -0,0 +1,75 @@ +/***************************************************************************** + * Copyright (c) 2014-2018 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include "../Context.h" +#include "../Game.h" +#include "../GameState.h" +#include "../OpenRCT2.h" +#include "../core/Console.hpp" +#include "../network/network.h" +#include "../platform/platform.h" +#include "../world/Sprite.h" +#include "CommandLine.hpp" + +#include +#include + +using namespace OpenRCT2; + +static exitcode_t HandleSimulate(CommandLineArgEnumerator* argEnumerator); + +const CommandLineCommand CommandLine::SimulateCommands[]{ // Main commands + DefineCommand("", "", nullptr, HandleSimulate), CommandTableEnd +}; + +static exitcode_t HandleSimulate(CommandLineArgEnumerator* argEnumerator) +{ + const char** argv = (const char**)argEnumerator->GetArguments() + argEnumerator->GetIndex(); + int32_t argc = argEnumerator->GetCount() - argEnumerator->GetIndex(); + + if (argc < 2) + { + Console::Error::WriteLine("Missing arguments ."); + return EXITCODE_FAIL; + } + + core_init(); + + const char* inputPath = argv[0]; + uint32_t ticks = atol(argv[1]); + + gOpenRCT2Headless = true; + +#ifndef DISABLE_NETWORK + gNetworkStart = NETWORK_MODE_SERVER; +#endif + + std::unique_ptr context(CreateContext()); + if (context->Initialise()) + { + if (!context->LoadParkFromFile(inputPath)) + { + return EXITCODE_FAIL; + } + + Console::WriteLine("Running %d ticks...", ticks); + for (uint32_t i = 0; i < ticks; i++) + { + context->GetGameState()->UpdateLogic(); + } + Console::WriteLine("Completed: %s", sprite_checksum()); + } + else + { + Console::Error::WriteLine("Context initialization failed."); + return EXITCODE_FAIL; + } + + return EXITCODE_OK; +}