Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Libtiled tile read fix #2006
First of all thank you for contributing to libtiled-java! Step by step it will support TMX features added after I stopped coding in Java, like tile flipping. :-)
However, the current implementation is not going to be very memory-friendly, since it allocates a new Tile object for each flipped instance of a tile. Flip your entire map and each individual cell will end up pointing to its own uniquely allocated Tile instance, and due to for example its properties not being immutable, they will get cloned for each instance as well (even though tile properties really should be shared between flipped instances of a tile).
In Tiled I have solved this with a Cell structure, which points to a Tile and stores the flags. Maybe something similar would work in this case? Alternatively, a special cloning method could be used to avoid duplicating the properties, and a cache could be introduced to avoid creating multiple Tile instances with the same flags.
The image layer part of the change looks fine.
@iarkhanhelsky I'm very sorry, I forgot about this change for a long time despite your reminder. I just looked at it again and saw no reason not to merge these great improvements. Many thanks to @Sam-Manflame and @pvlbndrnk for the patches!
I see the last patch also includes the optimization discussed at #2089, so we can close that pull request. I still think that rather than a cache, we could create just a single