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 tilespec.cpp #450

Merged
merged 24 commits into from
Sep 12, 2021
Merged

Conversation

lmoureaux
Copy link
Contributor

@lmoureaux lmoureaux commented Apr 26, 2021

This is a major refactoring of the tileset drawing code to split it and simplify what can be. Hopefully at the end we get something much easier to work with.

The following layers have been ported:

  • LAYER_BACKGROUND
  • LAYER_SPECIAL*
  • LAYER_BASE_FLAGS
  • LAYER_DARKNESS
  • LAYER_TERRAIN*

The following layers have not yet been ported:

  • LAYER_WATER
  • LAYER_ROADS
  • LAYER_FOG
  • LAYER_UNIT
  • LAYER_CITY*
  • LAYER_GRID*
  • LAYER_BASE_FLAGS (which is new)
  • LAYER_OVERLAYS
  • LAYER_TILELABEL
  • LAYER_CITYBAR
  • LAYER_FOCUS_UNIT
  • LAYER_GOTO
  • LAYER_WORKERTASK
  • LAYER_EDITOR
  • LAYER_INFRAWORK

Features dropped:

Closes #430.

@lmoureaux lmoureaux self-assigned this Apr 26, 2021
@lmoureaux lmoureaux force-pushed the feature/split-tilespec-cpp branch 4 times, most recently from 6fc35fd to 1fab1f6 Compare August 30, 2021 01:25
@lmoureaux lmoureaux force-pushed the feature/split-tilespec-cpp branch from 1fab1f6 to 1dc71b0 Compare August 31, 2021 08:33
@lmoureaux
Copy link
Contributor Author

lmoureaux commented Sep 11, 2021

This is the bug that I'm currently having with Trident: [edit: fixed]
image

@lmoureaux
Copy link
Contributor Author

lmoureaux commented Sep 11, 2021

Found another bug, this one with amplio2 lakes: [edit: this one is fixed]
image

@lmoureaux
Copy link
Contributor Author

Simplify fill_basic_extra_sprite_array appears to be the commit introducing the Trident artifacts.

This allows to get rid of an idiom where functions would append sprites to an
array and return the number of new sprites. The hard-coded maximum of 80
sprites per call no longer exists, which enhances code safety.

This is a small step towards breaking down tilespec.cpp, see longturn#430.
The map drawing code will be modularized and layers can ~easily be abstracted
away.

See longturn#430.
This will allow removing the big switch() in fill_sprite_array().

See longturn#430.
Layers will soon become much more general. Free the name for a new variable.

See longturn#430.
This will make them more powerful.

See longturn#430.
Using the virtual function will allow to offload drawing code to subclasses.

See longturn#430.
This greatly simplifies the definition of ADD_SPRITE in the tileset code and
will make it easier to refactor it.

See longturn#430.
They are now simple enough to be replaced by direct calls to
sprs.emplace_back(). Of the old ADD_SPRITE macros, only ADD_SPRITE_FULL is
left.

See longturn#430.
The dedicated class layer_background is for now a tiny wrapper around
::fill_sprite_array that works only with LAYER_BACKGROUND. All the code for
LAYER_BACKGROUND will be moved to that class in a later commit.

See longturn#430.
This commit migrates the code to draw the LAYER_BACKGROUND sprites to the
layer_background class. The feature that allowed to hide the terrain was not
migrated; see longturn#449.

Closes longturn#449.
See longturn#430.
Extras with style "Single2" are only drawn on layer "Special2" (they don't have
two sprites as was implied by the comments).

Also remove some extraneous whitespace.
Instead of duplicating the drawing logic from fill_sprite_array, call
fill_sprite_array with a virtual tile that has only the requested extra set.
Adjustments were needed to make fill_sprite_array work with this kind of tiles.

As a consequence of this change, fill_basic_extra_sprite_array now returns
several sprites for shipped tilesets. The help dialog was adjusted to take them
all into account, with the limitation that the first sprite dictates the size
of the rest and relative offsets are not supported.
@lmoureaux lmoureaux force-pushed the feature/split-tilespec-cpp branch from 1dc71b0 to 2c3e56b Compare September 12, 2021 17:51
lmoureaux added a commit to lmoureaux/freeciv21 that referenced this pull request Sep 12, 2021
This prevents undefined behavior (in practice, artifacts with Trident).

See longturn#450.
@lmoureaux lmoureaux marked this pull request as ready for review September 12, 2021 17:53
lmoureaux added a commit to lmoureaux/freeciv21 that referenced this pull request Sep 12, 2021
This prevents undefined behavior (in practice, artifacts with Trident).

See longturn#450.
@lmoureaux lmoureaux force-pushed the feature/split-tilespec-cpp branch from 2c3e56b to 8b043b6 Compare September 12, 2021 18:03
This change allows significant deduplications. The drawing of Single1, Single2
and 3Layers specials is unified: each layer_special may or may not have sprites
for each special (which specials is decided when loading the tileset).

See longturn#430.
This re-enables the base flags lost in the previous commit.
The same switch(layer) was repeated twice. This was fine when there weren't too
many layers, but the amount of duplication grew when adding more. This commit
factors out the switch() to a new function.
They correspond to two variables declared at the beginning of
fill_sprite_array(), do_draw_unit and solid_bg, that are used by several layer
types.

See longturn#430.
This is a very large one with heavy refactoring. The code was split in smaller
functions, boosting readability. Documentation was also improved.

No new functionality was added. The unused is_reversed flag was dropped; it was
not used in any known tileset and layer_order provides a better alternative.
The factorization makes it very straightforward to add more than 3 terrain
layers, limited only by the tileset reading code.

All shipped tilesets load correctly.

See longturn#430.
info.matches_with contains two elements: the first is equal to info.group and
the second is the group being matched against. The first element was
erroneously used; use the second instead.

See longturn#430.
This prevents undefined behavior (in practice, artifacts with Trident).

See longturn#450.
@lmoureaux lmoureaux force-pushed the feature/split-tilespec-cpp branch from 8b043b6 to 2c3a4eb Compare September 12, 2021 18:11
@lmoureaux lmoureaux merged commit bc50af4 into longturn:master Sep 12, 2021
@lmoureaux lmoureaux deleted the feature/split-tilespec-cpp branch September 12, 2021 18:34
@lmoureaux lmoureaux mentioned this pull request Sep 13, 2021
psampathkumar pushed a commit to psampathkumar/freeciv21 that referenced this pull request Nov 14, 2021
This prevents undefined behavior (in practice, artifacts with Trident).

See longturn#450.
lmoureaux added a commit to lmoureaux/freeciv21 that referenced this pull request May 28, 2023
This is one of the failure modes of bad connections. Fail to connect after 30s
(Qt default). Related to longturn#450.
lmoureaux added a commit to lmoureaux/freeciv21 that referenced this pull request Jun 12, 2023
This is one of the failure modes of bad connections. Fail to connect after 30s
(Qt default). Related to longturn#450.
jwrober pushed a commit that referenced this pull request Jun 17, 2023
This is one of the failure modes of bad connections. Fail to connect after 30s
(Qt default). Related to #450.
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.

Restructure tilespec.cpp
1 participant