Merge pull request #6715 from Broxzier/screenshot_climate

Add optional screenshot argument to set weather
This commit is contained in:
Ted John 2017-11-25 23:32:35 +00:00 committed by GitHub
commit 84305af7ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 18 deletions

View File

@ -17,18 +17,33 @@
#include "../interface/Screenshot.h"
#include "CommandLine.hpp"
extern "C"
{
sint32 gScreenshotWeather = 0;
}
static uint32 _weather = 0;
static const CommandLineOptionDefinition ScreenshotOptions[]
{
{ CMDLINE_TYPE_INTEGER, &_weather, NAC, "weather", "weather to be used (0 = default, 1 = sunny, ..., 6 = thunder)." },
OptionTableEnd
};
static exitcode_t HandleScreenshot(CommandLineArgEnumerator *argEnumerator);
const CommandLineCommand CommandLine::ScreenshotCommands[]
{
// Main commands
DefineCommand("", "<file> <output_image> <width> <height> [<x> <y> <zoom> <rotation>]", nullptr, HandleScreenshot),
DefineCommand("", "<file> <output_image> giant <zoom> <rotation>", nullptr, HandleScreenshot),
DefineCommand("", "<file> <output_image> <width> <height> [<x> <y> <zoom> <rotation>]", ScreenshotOptions, HandleScreenshot),
DefineCommand("", "<file> <output_image> giant <zoom> <rotation>", ScreenshotOptions, HandleScreenshot),
CommandTableEnd
};
static exitcode_t HandleScreenshot(CommandLineArgEnumerator *argEnumerator)
{
gScreenshotWeather = _weather;
const char * * argv = (const char * *)argEnumerator->GetArguments() + argEnumerator->GetIndex();
sint32 argc = argEnumerator->GetCount() - argEnumerator->GetIndex();
sint32 result = cmdline_for_screenshot(argv, argc);

View File

@ -15,6 +15,7 @@
#pragma endregion
#include <chrono>
#include <cstdlib>
#include "../audio/audio.h"
#include "../Context.h"
#include "../core/Console.hpp"
@ -28,6 +29,7 @@
#include "../localisation/localisation.h"
#include "../platform/platform.h"
#include "../util/util.h"
#include "../world/Climate.h"
#include "viewport.h"
using namespace OpenRCT2;
@ -347,10 +349,21 @@ sint32 cmdline_for_gfxbench(const char **argv, sint32 argc)
sint32 cmdline_for_screenshot(const char **argv, sint32 argc)
{
bool giantScreenshot = argc == 5 && _stricmp(argv[2], "giant") == 0;
// Don't include options in the count (they have been handled by CommandLine::ParseOptions already)
for (sint32 i = 0; i < argc; i++)
{
if (argv[i][0] == '-')
{
// Setting argc to i works, because options can only be at the end of the command
argc = i;
break;
}
}
bool giantScreenshot = (argc == 5) && _stricmp(argv[2], "giant") == 0;
if (argc != 4 && argc != 8 && !giantScreenshot) {
printf("Usage: openrct2 screenshot <file> <ouput_image> <width> <height> [<x> <y> <zoom> <rotation>]\n");
printf("Usage: openrct2 screenshot <file> <ouput_image> giant <zoom> <rotation>\n");
std::printf("Usage: openrct2 screenshot <file> <ouput_image> <width> <height> [<x> <y> <zoom> <rotation>]\n");
std::printf("Usage: openrct2 screenshot <file> <ouput_image> giant <zoom> <rotation>\n");
return -1;
}
@ -361,31 +374,38 @@ sint32 cmdline_for_screenshot(const char **argv, sint32 argc)
const char *inputPath = argv[0];
const char *outputPath = argv[1];
if (giantScreenshot) {
if (giantScreenshot)
{
resolutionWidth = 0;
resolutionHeight = 0;
customLocation = true;
centreMapX = true;
centreMapY = true;
customZoom = atoi(argv[3]);
customRotation = atoi(argv[4]) & 3;
} else {
resolutionWidth = atoi(argv[2]);
resolutionHeight = atoi(argv[3]);
if (argc == 8) {
customZoom = std::atoi(argv[3]);
customRotation = std::atoi(argv[4]) & 3;
}
else
{
resolutionWidth = std::atoi(argv[2]);
resolutionHeight = std::atoi(argv[3]);
if (argc == 8)
{
customLocation = true;
if (argv[4][0] == 'c')
centreMapX = true;
else
customX = atoi(argv[4]);
customX = std::atoi(argv[4]);
if (argv[5][0] == 'c')
centreMapY = true;
else
customY = atoi(argv[5]);
customY = std::atoi(argv[5]);
customZoom = atoi(argv[6]);
customRotation = atoi(argv[7]) & 3;
} else {
customZoom = std::atoi(argv[6]);
customRotation = std::atoi(argv[7]) & 3;
}
else
{
customZoom = 0;
}
}
@ -395,7 +415,18 @@ sint32 cmdline_for_screenshot(const char **argv, sint32 argc)
if (context->Initialise())
{
drawing_engine_init();
context->LoadParkFromFile(inputPath);
try
{
context->LoadParkFromFile(inputPath);
}
catch (const std::exception &e)
{
std::printf("%s\n", e.what());
drawing_engine_dispose();
delete context;
return -1;
}
gIntroState = INTRO_STATE_NONE;
gScreenFlags = SCREEN_FLAGS_PLAYING;
@ -457,6 +488,20 @@ sint32 cmdline_for_screenshot(const char **argv, sint32 argc)
gCurrentRotation = gSavedViewRotation;
}
if (gScreenshotWeather != 0)
{
if (gScreenshotWeather < 1 || gScreenshotWeather > 6)
{
std::printf("Weather can only be set to an integer value from 1 till 6.");
drawing_engine_dispose();
delete context;
return -1;
}
uint8 customWeather = gScreenshotWeather - 1;
climate_force_weather(customWeather);
}
// Ensure sprites appear regardless of rotation
reset_all_sprite_quadrant_placements();

View File

@ -25,6 +25,7 @@ extern "C"
{
#endif
extern uint8 gScreenshotCountdown;
extern sint32 gScreenshotWeather;
void screenshot_check();
sint32 screenshot_dump();