Big improvements and optimizations for Tiled maps handling in TCastleScene

Tiled isometric map in CGE editor in TCastleScene
Tiled hexagonal map in TCastleScene
Tiled map with extra objects in TCastleScene
Big Tiled map (400x400) in TCastleScene
Tiled map in view3dscene
Tiled map in view3dscene in 3D

This post somewhat retracts yesterday’s post, because I had a busy sleepless night and fixed some issues with loading Tiled in TCastleScene that I mentioned yesterday 🙂 I did a significant refactor of how it works.

I’m proud to say that loading Tiled maps into TCastleScene is now our recommended approach to using Tiled maps. The big benefit of this approach is that you can place additional objects, like sprite sheets in TCastleScene, over the map easily (and specialized API to place/move units on map will appear soon too). TCastleTiledMapControl will soon be deprecated, in light of this.

The following improvements are done:

  1. First of all, we have new example application examples/tiled/map_viewer_in_viewport where you can test everything I announce today. It is a simple Tiled map viewer, underneath loading Tiled map to TCastleScene.

    You can test that it is functionally just as good, if not better, than examples/tiled/map_viewer approach.

  2. Huge optimization, by internally using a single draw call for all consecutive tiles using the same tileset. This allows to effortlessly support our test map 400×400 in examples/tiled/map_viewer_in_viewport/data/maps/desert_big.tmx with 100 FPS, at whatever zoom.

  3. Support for all map types: Orthogonal, Isometric, IsometricStaggered, Hexagonal.

  4. Correct support for all flip combinations (diagonal, horizontal, vertical).

  5. Fixed layer Z ordering and offset application for all layer types.

  6. Fixed origin (map left-bottom corner is now at 0,0).

  7. Support for “Smooth Scaling Safe Border”, to fix rendering artifacts when using smooth scaling on tilesets without proper alpha bleeding.

  8. I’m proud that my refactor actually made the code over 2x smaller and simpler 🙂 Line count dropped 1210 -> 510 for the x3dloadinternaltiledmap.pas unit.

If you like my sleepless nights’ work, please support us on Patreon 🙂

3 Likes