Skip to content

Commit

Permalink
Cherry-pick Yume 2kki patches (#40)
Browse files Browse the repository at this point in the history
* 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>

* 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>

---------

Co-authored-by: Ghabry <gabriel+github@mastergk.de>
  • Loading branch information
Desdaemon and Ghabry authored Sep 4, 2024
1 parent ca19ddd commit e5968ec
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Bitmap::Bitmap(Filesystem_Stream::InputStream stream, bool transparent, uint32_t

CheckPixels(flags);

filename = ToString(stream.GetName());
id = ToString(stream.GetName());
}

Bitmap::Bitmap(const uint8_t* data, unsigned bytes, bool transparent, uint32_t flags) {
Expand Down
28 changes: 21 additions & 7 deletions src/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

void CheckPixels(uint32_t flags);

Expand Down Expand Up @@ -597,7 +606,7 @@ class Bitmap {
TileOpacity tile_opacity;
Color bg_color, sh_color;

std::string filename;
std::string id;

/** Bitmap data. */
PixmanImagePtr bitmap;
Expand Down Expand Up @@ -668,8 +677,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;
}

#endif
10 changes: 7 additions & 3 deletions src/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace {
std::unordered_map<tile_key_type, std::weak_ptr<Bitmap>> cache_tiles;

// rect, flip_x, flip_y, tone, blend
using effect_key_type = std::tuple<Bitmap*, Rect, bool, bool, Tone, Color>;
using effect_key_type = std::tuple<std::string, Rect, bool, bool, Tone, Color>;
std::map<effect_key_type, std::weak_ptr<Bitmap>> cache_effects;

std::string system_name;
Expand Down Expand Up @@ -438,13 +438,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,
Expand Down
8 changes: 8 additions & 0 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2331,6 +2331,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;
};

Expand Down

0 comments on commit e5968ec

Please sign in to comment.