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

Fix map sharing #2055

Merged
merged 1 commit into from
Nov 27, 2023
Merged

Fix map sharing #2055

merged 1 commit into from
Nov 27, 2023

Conversation

lmoureaux
Copy link
Contributor

Sharing maps between players was fundamentally broken. The server records the last turn in which a player saw a tile. This information is only updated when the player stops seeing a tile, and not when it just keeps seeing it because the tile is within its vision range.

The following map sharing bugs existed:

  • Tiles seen by the giving player were not sent if the receiving player had last viewed them after the giving player;
  • Cities were only updated when destroyed. Renamed or growing cities were not updated.

This commit fixes both bugs. The core logic in really_give_tile_info_from_player_to_player was completely overhauled to make it easier to follow and more correct. In addition, player_tile.site was turned to a unique_ptr to facilitate bookkeeping.

Closes #2045

Testing: Before the patch:

  • Watch the occupied city indicator in a city. Move units in and out while giving your map to another player. See the indicator not being updated for the other player.
  • Same with city renaming.
  • If you are patient enough, repeat with city growth, terrain alterations, etc.

After the patch, the other player should always get the information at the time of signing the treaty.

Not suggesting to backport since the bugs had been there for a very long time.

@jeltsch
Copy link

jeltsch commented Nov 22, 2023

Tiles seen by the giving player were not sent if the receiving player had last viewed them after the giving player

Is this really a bug? I would expect that newer information doesn’t get overwritten with older information.

@lmoureaux
Copy link
Contributor Author

Tiles seen by the giving player were not sent if the receiving player had last viewed them after the giving player

Is this really a bug? I would expect that newer information doesn’t get overwritten with older information.

"Seen" tiles are the tiles currently visible by a player (as opposed to tiles that are merely "known")

@jwrober
Copy link
Collaborator

jwrober commented Nov 23, 2023

Looks like the PR is failing the clang-format checker.

@lmoureaux
Copy link
Contributor Author

Uh I see, the usual case not caught by git-clang-format

Sharing maps between players was fundamentally broken. The server records the
last turn in which a player saw a tile. This information is only updated when
the player stops seeing a tile, and not when it just keeps seeing it because
the tile is within its vision range.

The following map sharing bugs existed:
* Tiles seen by the giving player were not sent if the receiving player had
  last viewed them after the giving player;
* Cities were only updated when destroyed. Renamed or growing cities were not
  updated.

This commit fixes both bugs. The core logic in
really_give_tile_info_from_player_to_player was completely overhauled to make
it easier to follow and more correct. In addition, player_tile.site was turned
to a unique_ptr to facilitate bookkeeping.
@lmoureaux
Copy link
Contributor Author

clang-format fixed

@jeltsch
Copy link

jeltsch commented Nov 23, 2023

Tiles seen by the giving player were not sent if the receiving player had last viewed them after the giving player

Is this really a bug? I would expect that newer information doesn’t get overwritten with older information.

"Seen" tiles are the tiles currently visible by a player (as opposed to tiles that are merely "known")

Then I don’t understand this even more. If the seen tiles are currently visible to the player, they are viewed now. How can then the other player have them last viewed at a later time?

@lmoureaux
Copy link
Contributor Author

The two players are usually not sharing vision, as this is related to the treaty clauses to share one's map

@lmoureaux
Copy link
Contributor Author

Sorry, I missed the question in the second part. As an optimisation (I suppose), the "last viewed" info is not updated at every turn change. It gets updated only when vision is lost.

@jeltsch
Copy link

jeltsch commented Nov 24, 2023

Sorry, I missed the question in the second part. As an optimisation (I suppose), the "last viewed" info is not updated at every turn change. It gets updated only when vision is lost.

I must say that finally I’m utterly confused. I don’t know whether I’d like to help here further. This stuff seems so convoluted that I don’t really have further ambition to try to understand it. Sadly, I’m by no means convinced that the fix in this PR is actually suitable.

@jeltsch
Copy link

jeltsch commented Nov 24, 2023

Looking again at what “last viewed” means, it starts to make sense to me why the first point mentioned in the PR description could be a bug. Still, parts of the map where the receiving player has currently vision should not be sent. Is this taken into account by the updated code?

@lmoureaux
Copy link
Contributor Author

parts of the map where the receiving player has currently vision should not be sent. Is this taken into account by the updated code?

Yes, this is the first check:

  // No need to transfer if pdest can see the tile
  if (map_is_known_and_seen(ptile, pdest, V_MAIN)) {
    return;
  }

I'd be interested if you have ideas for a simpler implementation

@jeltsch
Copy link

jeltsch commented Nov 26, 2023

I'd be interested if you have ideas for a simpler implementation

At least not spontaneously. :slightly_smiling_face:

@lmoureaux
Copy link
Contributor Author

@jwrober can you review then?

@jwrober
Copy link
Collaborator

jwrober commented Nov 26, 2023

@jwrober can you review then?

Yep. Prolly tomorrow. Will need to setup a test.

@lmoureaux
Copy link
Contributor Author

Thanks!

Copy link
Collaborator

@jwrober jwrober left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. Nice patch!

@lmoureaux lmoureaux merged commit 64f8e7f into longturn:master Nov 27, 2023
19 of 20 checks passed
@lmoureaux lmoureaux deleted the bugfix/map-sharing branch November 27, 2023 23:20
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.

Map data transfer in need of thorough review
3 participants