mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-27 00:34:46 +01:00
Merge pull request #25662 from mixiate/improve-sprite-build-speed
Improve sprite build cli command performance when using sprite sheets
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
- Improved: [#25575] Updated the network protocol to a new format that supports larger packets, allowing clients to connect reliably to servers with many objects or large maps.
|
||||
- Improved: [#25621] Added the Polish Złoty (PLN) to the list of available currencies.
|
||||
- Improved: [#25625] Renewing and refurbishing rides now also resets the downtime.
|
||||
- Improved: [#25662] The sprite build command is faster when building sprites from the same image file.
|
||||
- Change: [#21912] Toilet income is now categorised as shop sales instead of ride tickets.
|
||||
- Change: [#25403] Guests will not slide down the Spiral Slide if it's broken, even if they have already entered the ride structure.
|
||||
- Change: [#25485] Make the enlarged pressed swatch sprite more pronounced.
|
||||
|
||||
@@ -52,9 +52,11 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
|
||||
constexpr uint8_t importFlags = EnumToFlag(ImportFlags::RLE);
|
||||
ImageImportMeta meta = { { xOffset, yOffset }, Palette::OpenRCT2, importFlags, spriteMode };
|
||||
auto importResult = SpriteImageImport(imagePath, meta);
|
||||
if (!importResult.has_value())
|
||||
const auto image = SpriteImageLoad(imagePath, meta);
|
||||
if (!image.has_value())
|
||||
return -1;
|
||||
ImageImporter importer;
|
||||
auto importResult = importer.Import(image.value(), meta);
|
||||
|
||||
auto spriteFile = SpriteFile::Open(spriteFilePath);
|
||||
if (!spriteFile.has_value())
|
||||
@@ -63,7 +65,7 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
return -1;
|
||||
}
|
||||
|
||||
spriteFile->AddImage(importResult.value());
|
||||
spriteFile->AddImage(importResult);
|
||||
|
||||
if (!spriteFile->Save(spriteFilePath))
|
||||
return -1;
|
||||
|
||||
@@ -62,6 +62,8 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
|
||||
uint32_t numSuccessful = 0;
|
||||
|
||||
std::unordered_map<u8string, Image> images{};
|
||||
|
||||
// Note: jsonSprite is deliberately left non-const: json_t behaviour changes when const
|
||||
for (auto& [jsonKey, jsonSprite] : jsonSprites.items())
|
||||
{
|
||||
@@ -84,14 +86,28 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
|
||||
auto imagePath = Path::GetAbsolute(Path::Combine(directoryPath, strPath));
|
||||
|
||||
auto importResult = SpriteImageImport(imagePath, meta);
|
||||
if (importResult == std::nullopt)
|
||||
const auto image_iter = images.find(imagePath);
|
||||
if (image_iter != images.end())
|
||||
{
|
||||
fprintf(stderr, "Could not import image file: %s\nCanceling\n", imagePath.c_str());
|
||||
return -1;
|
||||
ImageImporter importer;
|
||||
auto importResult = importer.Import(image_iter->second, meta);
|
||||
spriteFile.AddImage(importResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto image = SpriteImageLoad(imagePath, meta);
|
||||
if (image == std::nullopt)
|
||||
{
|
||||
fprintf(stderr, "Could not read image file: %s\nCanceling\n", imagePath.c_str());
|
||||
return -1;
|
||||
}
|
||||
images[imagePath] = image.value();
|
||||
|
||||
spriteFile.AddImage(importResult.value());
|
||||
ImageImporter importer;
|
||||
auto importResult = importer.Import(image.value(), meta);
|
||||
|
||||
spriteFile.AddImage(importResult);
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
fprintf(stdout, "Added: %s\n", imagePath.c_str());
|
||||
|
||||
@@ -162,7 +162,7 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<ImageImporter::ImportResult> SpriteImageImport(u8string_view path, ImageImportMeta meta)
|
||||
std::optional<Image> SpriteImageLoad(u8string_view path, ImageImportMeta meta)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -171,11 +171,7 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
{
|
||||
format = ImageFormat::png;
|
||||
}
|
||||
|
||||
ImageImporter importer;
|
||||
auto image = Imaging::ReadFromFile(path, format);
|
||||
|
||||
return importer.Import(image, meta);
|
||||
return Imaging::ReadFromFile(path, format);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
{
|
||||
using namespace OpenRCT2::Drawing;
|
||||
bool SpriteImageExport(const G1Element& spriteElement, u8string_view outPath);
|
||||
std::optional<ImageImporter::ImportResult> SpriteImageImport(u8string_view path, ImageImportMeta meta);
|
||||
std::optional<Image> SpriteImageLoad(u8string_view path, ImageImportMeta meta);
|
||||
std::string PopStr(std::ostringstream& oss);
|
||||
|
||||
int32_t append(const char** argv, int32_t argc, ImportMode spriteMode);
|
||||
|
||||
Reference in New Issue
Block a user