Skip to content

Fix focusing on entities on the main viewport#3152

Merged
AaronVanGeffen merged 2 commits intoOpenLoco:masterfrom
LeeSpork:irrelevantly-empty-saved-view
Sep 30, 2025
Merged

Fix focusing on entities on the main viewport#3152
AaronVanGeffen merged 2 commits intoOpenLoco:masterfrom
LeeSpork:irrelevantly-empty-saved-view

Conversation

@LeeSpork
Copy link
Copy Markdown
Contributor

@LeeSpork LeeSpork commented Jul 16, 2025

Removes savedView.isEmpty() checks from Window methods related to focusing viewports on entities, as they served no clear purpose (correct me if I'm wrong!) and caused following (and unfollowing) vehicles on the main view to not work.

Fixes #3135

@AaronVanGeffen AaronVanGeffen requested a review from LeftofZen July 16, 2025 09:31
@AaronVanGeffen AaronVanGeffen added this to the v25.07+ milestone Aug 14, 2025
@AaronVanGeffen
Copy link
Copy Markdown
Member

AaronVanGeffen commented Aug 14, 2025

Removing savedView.isEmpty() is not the right approach. The check is necessary to see if an entity is being followed!

What's going wrong here is that SavedView::entityId used to share its memory with mapX. As of #3119 (June 2025) it no longer does, leading to the entityId property being ignored somewhere down the line. Reverting fc8eac2 fixes the issue, but that doesn't sit right with me either.

@ZehMatt, could you look into this?

@AaronVanGeffen AaronVanGeffen changed the title Remove savedView.isEmpty() checks to fix focusing on entities on the main viewport Fix focusing on entities on the main viewport Aug 14, 2025
@duncanspumpkin
Copy link
Copy Markdown
Contributor

Removing savedView.isEmpty() is not the right approach. The check is necessary to see if an entity is being followed!

What's going wrong here is that SavedView::entityId used to share its memory with mapX. As of #3119 (June 2025) it no longer does, leading to the entityId property being ignored somewhere down the line. Reverting fc8eac2 fixes the issue, but that doesn't sit right with me either.

@ZehMatt, could you look into this?

I've had a look and this does make sense as this is for the main window which doesn't have a saved view so the saved view is always empty. The being followed state is being stored in viewportConfigurations[0].viewportTargetSprite which is unlike all the other windows which store it in the saved view. The reason reverting fc8eac2 works is that before that we didn't initialise the saved view to empty we initialised it to 0 which is a valid value. So either we remove all the isEmpty checks that previously were reading invalid memory or we setup the saved view to actually store the entity. Why we have two things that store the entity is another question.

@duncanspumpkin
Copy link
Copy Markdown
Contributor

duncanspumpkin commented Aug 24, 2025

Removing savedView.isEmpty() is not the right approach. The check is necessary to see if an entity is being followed!
What's going wrong here is that SavedView::entityId used to share its memory with mapX. As of #3119 (June 2025) it no longer does, leading to the entityId property being ignored somewhere down the line. Reverting fc8eac2 fixes the issue, but that doesn't sit right with me either.
@ZehMatt, could you look into this?

I've had a look and this does make sense as this is for the main window which doesn't have a saved view so the saved view is always empty. The being followed state is being stored in viewportConfigurations[0].viewportTargetSprite which is unlike all the other windows which store it in the saved view. The reason reverting fc8eac2 works is that before that we didn't initialise the saved view to empty we initialised it to 0 which is a valid value. So either we remove all the isEmpty checks that previously were reading invalid memory or we setup the saved view to actually store the entity. Why we have two things that store the entity is another question.

So i think the main issue is that the main window doesn't operate like all the others and the viewport focus on main code hasn't accounted for the fact it doesn't work the same. Either we should make main work like all the other windows or we should remove these checks and rename the functions to make it clear they are only for use with main.

Here is my proposed patch that moves the function to make it clear its for working on main only
moveFunctions.patch

@duncanspumpkin duncanspumpkin modified the milestones: v25.07+, v25.08+ Aug 26, 2025
LeeSpork and others added 2 commits September 30, 2025 08:20
It said viewportCentreMain() could be const

Update CHANGELOG.md

Code comment accuracy
@duncanspumpkin duncanspumpkin force-pushed the irrelevantly-empty-saved-view branch from a16785a to 404e029 Compare September 30, 2025 07:33
@duncanspumpkin
Copy link
Copy Markdown
Contributor

I've applied my suggested change of movign the functions. Think this is now good to go.

@AaronVanGeffen AaronVanGeffen merged commit e4ffe18 into OpenLoco:master Sep 30, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Follow vehicle on main view no longer works

3 participants