LdtkRuleRunner
ceramic.LdtkRuleRunner (Class)
Recomputes the auto tiles of an LDtk layer instance at runtime, with the same rule engine as the LDtk editor
(ldtk.rules), so that a modified IntGrid produces exactly the tiles the editor would produce.
One runner per layer instance, kept on LdtkLayerInstance.ruleRunner. The engine, the IntGrid source,
the tile store and the rule list are created once and reused: recomputing does not allocate.
When incremental is true (default), compute() only recomputes the cells around the IntGrid changes
made since the previous compute (the dirty rect tracked by LdtkLayerInstance.setIntGrid(), expanded by the
maximum rule radius), which gives exactly the same tiles as a full recompute. A full recompute happens when the
rules, the seed or the killing layer changed, or when the dirty rect cannot be trusted: several runners may read
the same IntGrid, so the rect is only cleared by refreshAutoLayersUsingSource() once every reader was refreshed.
Typical use:
intGridLayer.setIntGrid(cx, cy, 1);
LdtkRuleRunner.refreshAutoLayersUsingSource(level, intGridLayer, tilemapVisual);
Static Members
Get (or create) the runner of a layer
true if this layer has rules that can be computed at runtime
Recompute the auto tiles of a layer from its current IntGrid, update autoLayerTiles, refresh the
TilemapLayerData and mark the layers of tilemap displaying it as dirty.
Returns false if the layer has no usable rules.
Refresh every auto layer of level that reads the IntGrid of intGridLayer (including itself if it is an auto layer),
then forget the pending IntGrid changes of intGridLayer (every reader has seen them).
Returns the number of refreshed layers.
Instance Members
The auto layer computed by this runner
The layer providing the IntGrid values (the layer itself, or its auto source layer)
Last computed tiles, indexed by cell (ldtk.rules.CellTileBuffer)
When true, compute() recomputes only the area of the IntGrid modified since the previous compute when possible
ldtk
lastComputeWasPartial: Bool
true if the last compute() was a partial recompute (false after a full one)
ldtk
lastComputeCells: Int
Number of cells evaluated by the last compute() (0 when nothing had changed)
ldtk
invalidateRules(): Void
Call this when the optional rule groups of the layer or the level biome field changed
ldtk
updateKilledCells(): Void
Call this when the tiles of the layer killing auto tiles changed
Compute the tiles of the layer into store: everything, or only the cells around the IntGrid changes made
since the previous compute when incremental is true and the dirty rect of the source layer can be used.
Does nothing if nothing changed since the previous compute.
Write the last computed tiles into layer.autoLayerTiles (same stride 7 layout as when loaded from LDtk:
tile id, flip bits, x, y, source x, source y, alpha * 4096), reusing the existing array.
ldtk
getTilePivotX(): Float
ldtk
getTilePivotY(): Float
Private Members
ldtk
lastIntGridVersion: Int