Saving worldmap position on unstable tiles#3766
Open
joanasaraiva10 wants to merge 1 commit intoSuperTux:masterfrom
Open
Saving worldmap position on unstable tiles#3766joanasaraiva10 wants to merge 1 commit intoSuperTux:masterfrom
joanasaraiva10 wants to merge 1 commit intoSuperTux:masterfrom
Conversation
Author
|
@tobbi Hi! I was wondering if you could check my PR as a few weeks have passed since I opened it. I would also like to know what can I do for the 2 failing checks to pass. |
Member
|
Can you please rebase against master? |
When leaving to the main menu, the game saves Tux's current worldmap position even if he is mid-path or on a non-stable tile. Upon reloading, Tux is restored to that invalid position. Save Tux on the last valid "stable" tile (such as a stop or level tile) instead of the current one. Also store the corresponding back direction to keep movement consistent after loading. In ghost mode, avoid persisting invalid tiles by falling back to the last valid level tile. This ensures Tux always respawns on a valid, navigable position.
8df7886 to
8546b2c
Compare
MatusGuy
requested changes
Apr 29, 2026
| m_worldmap->set_passive_message({}, 0.0f); | ||
| } | ||
|
|
||
| if (const auto level = worldmap_sector->at_object<LevelTile>(); level) |
Contributor
There was a problem hiding this comment.
[...]
; level[...]
Pardon?
In general, I would avoid declaring variables in if statements to improve clarity. Even with that in mind, it doesn't even seem like it is necessary in this case.
Suggested change
| if (const auto level = worldmap_sector->at_object<LevelTile>(); level) | |
| if (worldmap_sector->at_object<LevelTile>()) |
Comment on lines
+311
to
+327
| if (const auto level = worldmap_sector->at_object<LevelTile>(); level) | ||
| { | ||
| m_last_level_tile_pos = m_tile_pos; | ||
| m_last_level_back_direction = m_back_direction; | ||
| m_last_stable_tile_pos = m_tile_pos; | ||
| m_last_stable_back_direction = m_back_direction; | ||
| } | ||
| else if (!m_ghost_mode) | ||
| { | ||
| m_last_stable_tile_pos = m_tile_pos; | ||
| m_last_stable_back_direction = m_back_direction; | ||
| } | ||
| else | ||
| { | ||
| m_last_stable_tile_pos = m_last_level_tile_pos; | ||
| m_last_stable_back_direction = m_last_level_back_direction; | ||
| } |
Contributor
There was a problem hiding this comment.
In fact, I believe this could be written in a more concise manner.
Suggested change
| if (const auto level = worldmap_sector->at_object<LevelTile>(); level) | |
| { | |
| m_last_level_tile_pos = m_tile_pos; | |
| m_last_level_back_direction = m_back_direction; | |
| m_last_stable_tile_pos = m_tile_pos; | |
| m_last_stable_back_direction = m_back_direction; | |
| } | |
| else if (!m_ghost_mode) | |
| { | |
| m_last_stable_tile_pos = m_tile_pos; | |
| m_last_stable_back_direction = m_back_direction; | |
| } | |
| else | |
| { | |
| m_last_stable_tile_pos = m_last_level_tile_pos; | |
| m_last_stable_back_direction = m_last_level_back_direction; | |
| } | |
| if (worldmap_sector->at_object<LevelTile>() != nullptr) | |
| { | |
| m_last_level_tile_pos = m_tile_pos; | |
| m_last_level_back_direction = m_back_direction; | |
| } | |
| m_last_stable_tile_pos = m_ghost_mode ? m_last_level_tile_pos : m_tile_pos; | |
| m_last_stable_back_direction = m_ghost_mode ? m_last_level_back_direction : m_back_direction; |
Please make sure to double-check this logic.
| log_warning << "Player position not set, respawning." << std::endl; | ||
| sector.move_to_spawnpoint(DEFAULT_SPAWNPOINT_NAME); | ||
| m_position_was_reset = true; | ||
| return; |
Contributor
There was a problem hiding this comment.
Excuse me. I don't understand why this is here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When leaving to the main menu, the game saves Tux's current worldmap position even if he is mid-path or on a non-stable tile. Upon reloading, Tux is restored to that invalid position. Save Tux on the last valid "stable" tile (such as a stop or level tile) instead of the current one. Also store the corresponding back direction to keep movement consistent after loading. In ghost mode, avoid persisting invalid tiles by falling back to the last valid level tile. This ensures Tux always respawns on a valid, navigable position.
Closes #3728