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

Name Type
layer LdtkLayerInstance
Returns
LdtkRuleRunner

ldtk
canRun(layer: LdtkLayerInstance): Bool

true if this layer has rules that can be computed at runtime

Name Type
layer LdtkLayerInstance
Returns
Bool

ldtk
refreshAutoLayer(layer: LdtkLayerInstance, ?tilemap: Tilemap): Bool

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.

Name Type Default
layer LdtkLayerInstance
tilemap Tilemap (optional)
Returns
Bool

ldtk
refreshAutoLayersUsingSource(level: LdtkLevel, intGridLayer: LdtkLayerInstance, ?tilemap: Tilemap): Int

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.

Name Type Default
level LdtkLevel
intGridLayer LdtkLayerInstance
tilemap Tilemap (optional)
Returns
Int

Instance Members

The auto layer computed by this runner


ldtk
sourceLayer: LdtkLayerInstance

The layer providing the IntGrid values (the layer itself, or its auto source layer)


Last computed tiles, indexed by cell (ldtk.rules.CellTileBuffer)


ldtk
incremental: Bool

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.

Returns
ldtk.rules.CellTileBuffer

ldtk
writeAutoLayerTiles(): Array<Int>

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.

Returns
Array<Int>

ldtk
getSeed(): Int
Returns
Int

ldtk
getGridSize(): Int
Returns
Int

ldtk
getTilePivotX(): Float
Returns
Float

ldtk
getTilePivotY(): Float
Returns
Float

ldtk
getWidth(): Int
Returns
Int

ldtk
getHeight(): Int
Returns
Int

ldtk
isCellKilled(cx: Int, cy: Int): Bool
Name Type
cx Int
cy Int
Returns
Bool

Private Members



ldtk
tileset: LdtkRuleTileset

ldtk
rulesEval: Array<ldtk.rules.RuleDef>

ldtk
rulesDirty: Bool

ldtk
optionalRules: Map

ldtk
lastIntGridVersion: Int

ldtk
lastSeed: Int

ldtk
killedDirty: Bool

ldtk
computedOnce: Bool

ldtk
killerLayer: LdtkLayerInstance

ldtk
killed: haxe.ds.Vector<Bool>

ldtk
resolveSourceLayer(layer: LdtkLayerInstance): LdtkLayerInstance
Name Type
layer LdtkLayerInstance
Returns
LdtkLayerInstance

ldtk
findLayerByDefUid(level: LdtkLevel, defUid: Int): LdtkLayerInstance
Name Type
level LdtkLevel
defUid Int
Returns
LdtkLayerInstance

ldtk
updateRules(): Void

ldtk
biomeValues(): Null<Array<String>>
Returns
Null<Array<String>>

ldtk
new(layer: LdtkLayerInstance): Void
Name Type
layer LdtkLayerInstance