diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 59c3d3d38a..6b1b2c054f 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -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. diff --git a/src/openrct2/command_line/sprite/SpriteAppend.cpp b/src/openrct2/command_line/sprite/SpriteAppend.cpp index a3a581da52..90e635d9c7 100644 --- a/src/openrct2/command_line/sprite/SpriteAppend.cpp +++ b/src/openrct2/command_line/sprite/SpriteAppend.cpp @@ -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; diff --git a/src/openrct2/command_line/sprite/SpriteBuild.cpp b/src/openrct2/command_line/sprite/SpriteBuild.cpp index d3bf7428ea..951313ab78 100644 --- a/src/openrct2/command_line/sprite/SpriteBuild.cpp +++ b/src/openrct2/command_line/sprite/SpriteBuild.cpp @@ -62,6 +62,8 @@ namespace OpenRCT2::CommandLine::Sprite uint32_t numSuccessful = 0; + std::unordered_map 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()); diff --git a/src/openrct2/command_line/sprite/SpriteCommands.cpp b/src/openrct2/command_line/sprite/SpriteCommands.cpp index 018261b725..ea28f4e67e 100644 --- a/src/openrct2/command_line/sprite/SpriteCommands.cpp +++ b/src/openrct2/command_line/sprite/SpriteCommands.cpp @@ -162,7 +162,7 @@ namespace OpenRCT2::CommandLine::Sprite } } - std::optional SpriteImageImport(u8string_view path, ImageImportMeta meta) + std::optional 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) { diff --git a/src/openrct2/command_line/sprite/SpriteCommands.h b/src/openrct2/command_line/sprite/SpriteCommands.h index 0a24147e6b..b80ea1deaf 100644 --- a/src/openrct2/command_line/sprite/SpriteCommands.h +++ b/src/openrct2/command_line/sprite/SpriteCommands.h @@ -23,7 +23,7 @@ namespace OpenRCT2::CommandLine::Sprite { using namespace OpenRCT2::Drawing; bool SpriteImageExport(const G1Element& spriteElement, u8string_view outPath); - std::optional SpriteImageImport(u8string_view path, ImageImportMeta meta); + std::optional SpriteImageLoad(u8string_view path, ImageImportMeta meta); std::string PopStr(std::ostringstream& oss); int32_t append(const char** argv, int32_t argc, ImportMode spriteMode);