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

Refactor unit map layers #1083

Merged
merged 10 commits into from
Jul 9, 2022
Merged

Conversation

lmoureaux
Copy link
Contributor

This PR refactors the code that draws units on the map and some code around it. I wanted to implement #429 but figured that some refactoring was needed first. This PR introduces no behavior change.

Things to check

  • Are units still drawn where they should?
  • Do options like drawing only the focused unit still work as intended?
  • Does it crash?

lmoureaux added 3 commits July 5, 2022 23:23
Encapsulating unit drawing in a class will allow for more complex options
because it reduces the conceptual complexity of the code.
If one wants to draw a unit type, there's a very fitting function
get_unittype_sprite in the tileset. There is no reason for the map view to
duplicate this functionality with another implementation.
They were no longer used.  This commit also removes the unit type parameter
from fill_sprite_array functions, which was also never used.
@lmoureaux lmoureaux added refactoring This issue requires code refactoring gui This issue requires changes to the user interface labels Jul 6, 2022
@lmoureaux lmoureaux requested a review from psampathkumar July 6, 2022 22:58
lmoureaux added 6 commits July 7, 2022 01:00
It's used only once in the function.  What was the reason for making it a
parameter in the first place?
It was only ever set to tile_city(ptile).  It is better to call it in the
implementation, otherwise one could wonder when pcity isn't the city on the
tile being drawn.
'backdrop' was made useless when removing 'pcity'.
We have layer::do_draw_unit, so use it.  Also simplify away the XOR.
@lmoureaux lmoureaux force-pushed the refactor/layer_units branch from 519674c to 816a04e Compare July 6, 2022 23:00
Only those units that are focused should be drawn on the corresponding layer.
Copy link
Contributor

@psampathkumar psampathkumar left a comment

Choose a reason for hiding this comment

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

Take this chance to move layers to a separate folder ? I think something like, client/layers/layer_*.cpp/h is better. But I'll approve anyways, since that can be done in a different PR, where we reorganize everything within client. Apart from that, rest look good to me.

@lmoureaux
Copy link
Contributor Author

Thanks for the review! I agree that layer classes should eventually be moved to another folder, but I'm not sure how to call it: it could be for instance tileset/layers or simply tileset next to related classes. It's the only folder that I'm sure of, so I'm leaving this for later.

@lmoureaux lmoureaux merged commit 725b4d5 into longturn:master Jul 9, 2022
@lmoureaux lmoureaux deleted the refactor/layer_units branch July 9, 2022 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gui This issue requires changes to the user interface refactoring This issue requires code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants