From a27661ca45f5ddc89eb270ae9568790b9c0a8b7d Mon Sep 17 00:00:00 2001 From: Ghabry Date: Wed, 28 Aug 2024 10:01:21 +0200 Subject: [PATCH 1/2] Fix flickering in Yume2kki on map 3D Underworld (ID 1884). The map uses a MoveRoute with a jump and SetVehicleLocation for party movement in a tight loop which causes heavy flickering in our Player. This fix does not appear to be completely correct as RPG_RT does not reset the jump flag here but the "damage" is reduced because SetVehicleLocation -1 cannot happen without patching the game. Fix #3254 Co-Authored-By: Viet Dinh <54ckb0y789@gmail.com> --- src/game_interpreter.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 84dc8748fd..45b6bf34e7 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -2329,6 +2329,14 @@ bool Game_Interpreter::CommandSetVehicleLocation(lcf::rpg::EventCommand const& c vehicle->MoveTo(map_id, x, y); } Main_Data::game_player->MoveTo(map_id, x, y); + if (vehicle_id == 0) { + // This fixes a bug in Yume2kki on map 3D Underworld (ID 1884) + // The map uses a MoveRoute with a jump and SetVehicleLocation for party movement in a tight loop which + // causes heavy flickering in our Player. + // TODO: This fix does not appear to be completely correct as RPG_RT does not reset the jump flag here + // but the "damage" is reduced because SetVehicleLocation -1 cannot happen without patching the game. + Main_Data::game_player->SetJumping(false); + } return true; }; From 2fa20b91d8263409cbf572cefaded94b0f5acdc4 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Wed, 28 Aug 2024 10:13:31 +0200 Subject: [PATCH 2/2] Effects: Use the filename for the cache, not the bitmap pointer The pointer can be reused by a new bitmap and cause wrong animations. For individual tiles the filename is lost. "filename" in bitmap was renamed to "id" and gets now filename+tileid in that case. Fix #3256 Co-Authored-By: Viet Dinh <54ckb0y789@gmail.com> --- src/bitmap.cpp | 2 +- src/bitmap.h | 28 +++++++++++++++++++++------- src/cache.cpp | 10 +++++++--- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/bitmap.cpp b/src/bitmap.cpp index c7785efbd0..cd6d4f2d9c 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -129,7 +129,7 @@ Bitmap::Bitmap(Filesystem_Stream::InputStream stream, bool transparent, uint32_t original_bpp = image_out.bpp; - filename = ToString(stream.GetName()); + id = ToString(stream.GetName()); } Bitmap::Bitmap(const uint8_t* data, unsigned bytes, bool transparent, uint32_t flags) { diff --git a/src/bitmap.h b/src/bitmap.h index e10fb14268..2e191916d7 100644 --- a/src/bitmap.h +++ b/src/bitmap.h @@ -217,12 +217,21 @@ class Bitmap { Color GetShadowColor() const; /** - * Gets the filename this bitmap was loaded from. - * This will be empty when the origin was not a file. + * Returns an identifier for the bitmap. + * When the bitmap was loaded from a file this contains the filename. + * In all other cases this is implementation defined (and can be empty). * - * @return filename + * @return Bitmap identifier */ - StringView GetFilename() const; + StringView GetId() const; + + /** + * Sets the identifier of the bitmap. + * To avoid bugs the function will reject changing non-empty IDs. + * + * @param id new identifier + */ + void SetId(std::string id); /** * Gets bpp of the source image. @@ -608,7 +617,7 @@ class Bitmap { Color bg_color, sh_color; FontRef font; - std::string filename; + std::string id; /** Bpp of the source image */ int original_bpp; @@ -689,8 +698,13 @@ inline bool Bitmap::GetTransparent() const { return format.alpha_type != PF::NoAlpha; } -inline StringView Bitmap::GetFilename() const { - return filename; +inline StringView Bitmap::GetId() const { + return id; +} + +inline void Bitmap::SetId(std::string id) { + assert(this->id.empty()); + this->id = id; } inline FontRef Bitmap::GetFont() const { diff --git a/src/cache.cpp b/src/cache.cpp index 9006b07f41..e5c93fef3c 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -82,7 +82,7 @@ namespace { std::unordered_map> cache_tiles; // rect, flip_x, flip_y, tone, blend - using effect_key_type = std::tuple; + using effect_key_type = std::tuple; std::map> cache_effects; std::string system_name; @@ -448,13 +448,17 @@ BitmapRef Cache::Tile(StringView filename, int tile_id) { rect.x += sub_tile_id % 6 * 16; rect.y += sub_tile_id / 6 * 16; - return(cache_tiles[key] = Bitmap::Create(*chipset, rect)).lock(); + auto bmp = Bitmap::Create(*chipset, rect); + bmp->SetId(fmt::format("{}/{}", chipset->GetId(), tile_id)); + cache_tiles[key] = bmp; + + return bmp; } else { return it->second.lock(); } } BitmapRef Cache::SpriteEffect(const BitmapRef& src_bitmap, const Rect& rect, bool flip_x, bool flip_y, const Tone& tone, const Color& blend) { const effect_key_type key { - src_bitmap.get(), + src_bitmap->GetId(), rect, flip_x, flip_y,