Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yume2kki fixes #3259

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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);

/**
* Gets bpp of the source image.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions src/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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 @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
Loading