AdamsLair / duality

a 2D Game Development Framework
https://adamslair.github.io/duality
MIT License
1.41k stars 290 forks source link

Investigate Glitches in Tilemaps Plugin #689

Closed ilexp closed 5 years ago

ilexp commented 5 years ago

Summary

While reviewing PR #687, @mfep found some unrelated issues with the Tilemaps plugin. Investigate and fix them.

as I looked into the PR related to the tilemaps plugin, I've noticed that it's in quite a bad shape. I didn't really have time to investigate them, but just FYI, here's some glitches I encountered. I don't think any of them is caused by the PR

  1. unknown circumstances, the tile paint tool does not paint the selected tile, but an other (!)
  2. unknown circumstances, the tile size property of the Tileset fails to update. On the tile palette it seems normal, but when drawn, 4 tiles draws in each grid position
  3. the little overlay which is supposed to indicate the currently hovered tile coordinates is blank and at a weird place (screenshot)

https://cdn.discordapp.com/attachments/229132318915297280/497131704536793108/Untitled.png

How to reproduce

ilexp commented 5 years ago

Looked into (3) and fixed it with the above commit. There was an overlay rendering routine that adjusted the state of a shared Canvas without resetting it afterwards, causing offset and rotation issues in rendered overlays.

The other two are of course still up for grabs 👍

helle253 commented 5 years ago

I'll take a look and see if I can get to the bottom of either of the other 2. @mfep Is there any additional information you can provide regarding reproduction steps and/or source of the issue? Thanks in advance :+1:

mfep commented 5 years ago

I could reproduce glitch no. 1. It's possible that this is related to issue 2. as well. Here's how:

  1. Create a Tilemap with a TilemapRenderer in the Scene
  2. Open the used Tileset in the Tileset Editor window
  3. Open the Main Texture object, and modify the X component of the Source Tile Size property
  4. Press tab into the Y component, and edit that as well. Notice, that the Apply and Revert buttons on the bottom of the Tileset Editor do gray out. So the naive user would think that everything is in order...
  5. Go back to edit the Tilemap. All of the painting tools draw a different tile, not the selected one.
helle253 commented 5 years ago

It looks like there are some other issues with the tile palette. When docking windows, sometimes the palette window infinitely. I am still unsure of the mechanisms, but it looks like when the scene camera and the tile palette are in the same dock, they don't play well together.

2018-10-15-20-14-50

Regarding step 4 in your repro steps, that looks like another issue entirely, and is likely the source of some bugs - When resizing the source tile size to the same proportions as they were before, (e.g. resizing from (8,8) to (16,16)) the apply/revert buttons are inactive. I don't see this issue when changing the proportions, however.

helle253 commented 5 years ago

Upon further investigation, part of the issue appears to be the hash function in Point2.cs:

return this.X.GetHashCode() ^ this.Y.GetHashCode();

when you are using a square source tile, which is not an unusual scenario, this hash is always 0. The tilemap editor uses hash codes to determine whether changes have been made, so it flags this as a non-change, since the hash codes now match again, even though the source tile size has changed.

Modifying the hash code calculations for tilemaps should do the trick.

helle253 commented 5 years ago

Further investigation is needed in to other tile painting issues. When the SourceTileSize is changed, it appears the tiles paint incorrectly. The original tilemap size was 32x32; 16x16 and 64x64 both exhibit odd behaviors:

ezgif-1-f5bf1b59b946

ezgif-1-fd8d29779e25

ilexp commented 5 years ago

Further investigation is needed in to other tile painting issues. When the SourceTileSize is changed, it appears the tiles paint incorrectly. The original tilemap size was 32x32; 16x16 and 64x64 both exhibit odd behaviors:

Can you verify this with a newly created tileset and repro steps? As changing the source tile size shifts how the source images are broken up into tiles, what you are observing could be correct behavior with "user caused incorrect data". For example, if tile indices are shifted, previous AutoTile settings could apply to different tiles in ways that no longer make sense visually.

ilexp commented 5 years ago

It looks like there are some other issues with the tile palette. When docking windows, sometimes the palette window infinitely. I am still unsure of the mechanisms, but it looks like when the scene camera and the tile palette are in the same dock, they don't play well together.

Can you file a new issue for this with the description and video you provided? I think you're right that this is something else entirely, probably better discussed in a new thread.

Great work investigating these issues so far btw 👍

ilexp commented 5 years ago

I believe that all Tilemap glitches have now been either fixed, or moved into their own issues. Closing this.

For reference, see #693, #690 and #694.