Posted June 01, 2018 by Thorbjørn Lindeijer
#Snapshot
The new multi-map world view that was released with last week's development snapshot now automatically refreshes when loading, unloading or changing a world file. A number of fixes have been made as well, the biggest being the proper flipping and rotating of multi-layer stamps.
If anybody had already updated to yesterday's 2018.05.31 build, please update again because unfortunately I had introduced a crash when rotating the current stamp.
For those who are interested I'm going to share a bit about some under the hood changes I recently made!
While working to fix some issues with the recently introduced multi-layer tile stamps, I realized that I needed a convenient way to iterate over all the tile layers of a map. I already had written a LayerIterator, but I really wanted to be able to use the range-based for loops that were introduced with C++11.
To enable this, I extended the LayerIterator class with some standard operators for iterators and added a LayerIteratorHelper class, which returns the begin and end of the range. Based on that change, we can now iterate tile layers as follows without allocating a temporary list:
for (Layer *layer : map->tileLayers()) {
auto tileLayer = static_cast<TileLayer*>(layer);
// do something with the tile layer
}
I don't like the need for the static_cast, and maybe in the future I will use templates to get rid of that. But it may be tricky, because the LayerIterator can filter on multiple layer types.
This week I also replaced QScopedPointer with std::unique_ptr, and last week I've replaced Qt's foreach macro with range-based for loops everywhere. Also, all connections made between objects are now using the new type-safe syntax instead of the previously string-based API that could not report errors at compile time. While you won't see any of this when using Tiled, it can sometimes help to avoid bugs and it can make the code easier to read.
I hope you found that interesting!