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 overmap special data #52234

Merged

Conversation

jbytheway
Copy link
Contributor

Summary

None

Purpose of change

Previously the two types of overmap special (fixed vs mutable) stored their data completely differently. The fixed data was inline, and the mutable data was via a pointer. And all the functions using those had to switch on the type to decide which to use. This style of code is ugly and error-prone.

Describe the solution

Refactor the code so that both types of special are instead derived classes from an abstract overmap_special_data class.

This helps clarify some situations that were not handled correctly in the mutable case. Mapgen arguments were not being gathered from mutable special overmaps, the dimensions were not being calculated properly, and they were not respecting the must_be_unexplored flag. The first two of these issues are now fixed; the last remains (but there's now a TODO about it).

Describe alternatives you've considered

Leaving things as they were.

Testing

Unit tests. Loaded a game and checked overmap generation still looks reasonable.

Additional context

@Maleclypse Maleclypse added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Map / Mapgen Overmap, Mapgen, Map extras, Map display labels Oct 11, 2021
@Maleclypse
Copy link
Member

Does refactoring get the infrastructure label? I wasn't sure so I added it.

src/overmap.cpp Outdated Show resolved Hide resolved
@jbytheway
Copy link
Contributor Author

Looks like I have a few clang-tidy issues. Will probably get to them later today.

Previously the two types of overmap special (fixed vs mutable) stored
their data completely differently.  The fixed data was inline, and the
mutable data was via a pointer.  And all the functions useing those had
to switch on the type to decide which to use.

Refactor the code so that both types of special are instead derived
classes from an abstract overmap_special_data class.

This helps clarify some situations that were not handled correctly in
the mutable case.  Mapgen arguments were not being gathered from mutable
special overmaps, the dimensions were not being calculated properly, and
they were not respecting the must_be_unexplored flag.  The first two of
these issues are now fixed; the last remains (but there's now a TODO
about it).
@jbytheway
Copy link
Contributor Author

clang-tidy issues resolved. One remaining CI failure looks unrelated.

@kevingranade kevingranade merged commit 7828927 into CleverRaven:master Oct 26, 2021
@jbytheway jbytheway deleted the overmap_special_refactoring branch November 3, 2021 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Map / Mapgen Overmap, Mapgen, Map extras, Map display
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants