refactor: enhance overworld entity properties and version handling

- Updated `UpdateMapProperties` methods across various entities (entrances, exits, items, sprites) to include an optional context parameter for improved area size detection.
- Introduced `OverworldVersionHelper` for centralized ROM version detection and feature gating, replacing scattered inline checks.
- Refactored coordinate calculations to utilize normalized map IDs, ensuring consistency and preventing data corruption.
- Enhanced exit properties to sync player positions and calculate scroll/camera values based on the overworld context.

Benefits:
- Streamlines entity property updates and improves compatibility with different ROM versions.
- Reduces code duplication and enhances maintainability by centralizing version checks.
- Ensures accurate coordinate calculations for overworld entities, improving overall functionality.
This commit is contained in:
scawful
2025-10-18 00:09:09 -04:00
parent 9f56728f80
commit 1e39df88a3
15 changed files with 546 additions and 282 deletions

View File

@@ -45,27 +45,29 @@ class OverworldItem : public GameEntity {
: bg2_(bg2), id_(id), room_map_id_(room_map_id) {
x_ = x;
y_ = y;
map_id_ = room_map_id;
map_id_ = room_map_id; // Store original map_id
entity_id_ = id;
entity_type_ = kItem;
int map_x = room_map_id - ((room_map_id / 8) * 8);
int map_y = room_map_id / 8;
// Use normalized map_id for coordinate calculations
uint8_t normalized_map_id = room_map_id % 0x40;
int map_x = normalized_map_id % 8;
int map_y = normalized_map_id / 8;
game_x_ = static_cast<uint8_t>(std::abs(x - (map_x * 512)) / 16);
game_y_ = static_cast<uint8_t>(std::abs(y - (map_y * 512)) / 16);
}
void UpdateMapProperties(uint16_t room_map_id) override {
void UpdateMapProperties(uint16_t room_map_id, const void* context = nullptr) override {
(void)context; // Not used by items currently
room_map_id_ = room_map_id;
if (room_map_id_ >= 64) {
room_map_id_ -= 64;
}
int map_x = room_map_id_ - ((room_map_id_ / 8) * 8);
int map_y = room_map_id_ / 8;
// Use normalized map_id for calculations (don't corrupt stored value)
uint8_t normalized_map_id = room_map_id % 0x40;
int map_x = normalized_map_id % 8;
int map_y = normalized_map_id / 8;
// Update game coordinates from world coordinates
game_x_ = static_cast<uint8_t>(std::abs(x_ - (map_x * 512)) / 16);
game_y_ = static_cast<uint8_t>(std::abs(y_ - (map_y * 512)) / 16);
}