RuleEngine
The auto-layer rule engine: matches rule patterns against a RuleSource IntGrid and produces tiles for a RuleTarget layer.
One engine per target layer instance, reusable. Hot paths never allocate.
Two output paths share the same matching and tile production code:
- the editor path works on an
AutoTileCachemap (per rule, per cell), supports partial recomputes (applyRulesInRect) and applies break-on-match as a final pass; - the runtime path writes into a reusable buffer and applies break-on-match on the fly:
computeAllfills aFlatTileBuffer,computeFullandcomputeRectfill aCellTileBufferwhich supports partial recomputes. All produce the same tiles.
Static Members
| Name | Type |
|---|---|
cache |
AutoTileCache |
ruleUid |
Int |
w |
Int |
cx |
Int |
cy |
Int |
wid |
Int |
hei |
Int |
clearRule(cache: AutoTileCache, ruleUid: Int): Void| Name | Type |
|---|---|
cache |
AutoTileCache |
ruleUid |
Int |
flatten(cache: AutoTileCache, rulesDisplayOrder: Array<RuleDef>): Array<FlatAutoTile>Tiles of the cache in a deterministic order: rules in display order, cells by ascending coordId
| Name | Type |
|---|---|
cache |
AutoTileCache |
rulesDisplayOrder |
Array<RuleDef> |
| Returns |
|---|
| Array<FlatAutoTile> |
toJsonTiles(flat: Array<FlatAutoTile>): Array<ldtk.Tile>Convert flattened tiles to the autoLayerTiles JSON format
| Name | Type |
|---|---|
flat |
Array<FlatAutoTile> |
| Returns |
|---|
| Array<ldtk.Tile> |
Instance Members
source: RuleSourcetarget: RuleTargettileset: RuleTilesetDoes the rule pattern match at given coord? dirX/dirY = -1 test the mirrored pattern.
| Name | Type | Default |
|---|---|---|
r |
RuleDef | |
cx |
Int | |
cy |
Int | |
dirX |
Int | 1 |
dirY |
Int | 1 |
| Returns |
|---|
| Bool |
applyRuleAt(sink: AutoTileSink, r: RuleDef, cx: Int, cy: Int): BoolCheck and apply a rule at given coord (all flip variants). Returns TRUE if the rule matched.
The sink must already be positioned on this rule (beginRule).
| Name | Type |
|---|---|
sink |
AutoTileSink |
r |
RuleDef |
cx |
Int |
cy |
Int |
| Returns |
|---|
| Bool |
Produce the tiles of a matched rule at given coord, for given matching flips (bit0=X, bit1=Y)
| Name | Type |
|---|---|
sink |
AutoTileSink |
r |
RuleDef |
cx |
Int |
cy |
Int |
flips |
Int |
computeAll(buffer: FlatTileBuffer, rulesEvalOrder: Array<RuleDef>): VoidCompute every tile of the layer into buffer (reset first), with break-on-match applied on the fly.
Tiles are stored rule by rule in evaluation order, cells row by row; iterate the segments backwards to get the display order.
| Name | Type |
|---|---|
buffer |
FlatTileBuffer |
rulesEvalOrder |
Array<RuleDef> |
computeFull(store: CellTileBuffer, rulesEvalOrder: Array<RuleDef>): IntCompute every tile of the layer into a cell indexed store (emptied first). Returns the number of computed cells.
| Name | Type |
|---|---|
store |
CellTileBuffer |
rulesEvalOrder |
Array<RuleDef> |
| Returns |
|---|
| Int |
computeRect(store: CellTileBuffer, rulesEvalOrder: Array<RuleDef>, cx: Int, cy: Int, wid: Int, hei: Int): IntRecompute the tiles of a rectangle of cells in a store previously filled by computeFull (or computeRect),
after the source IntGrid changed in that rectangle. The area is expanded by MAX_RADIUS so that every pattern
reading a modified cell is re-evaluated; break-on-match locks are reset and recomputed for these cells only.
The result is identical to a full recompute. Falls back to computeFull if the store does not match the layer
or if the rule list changed. Returns the number of recomputed cells.
| Name | Type |
|---|---|
store |
CellTileBuffer |
rulesEvalOrder |
Array<RuleDef> |
cx |
Int |
cy |
Int |
wid |
Int |
hei |
Int |
| Returns |
|---|
| Int |
applyRulesInRect(cache: AutoTileCache, rulesEvalOrder: Array<RuleDef>, cx: Int, cy: Int, wid: Int, hei: Int): VoidRecompute all rules in a rectangle (expanded to cover neighbouring patterns), then apply break-on-match on it
| Name | Type |
|---|---|
cache |
AutoTileCache |
rulesEvalOrder |
Array<RuleDef> |
cx |
Int |
cy |
Int |
wid |
Int |
hei |
Int |
applyAll(cache: AutoTileCache, rulesEvalOrder: Array<RuleDef>): VoidRecompute everything into an emptied cache
| Name | Type |
|---|---|
cache |
AutoTileCache |
rulesEvalOrder |
Array<RuleDef> |
applyRuleEverywhere(cache: AutoTileCache, r: RuleDef): VoidRecompute a single rule on the whole layer (break-on-match is NOT applied, the caller decides)
| Name | Type |
|---|---|
cache |
AutoTileCache |
r |
RuleDef |
applyBreakOnMatchesArea(cache: AutoTileCache, rulesEvalOrder: Array<RuleDef>, cx: Int, cy: Int, wid: Int, hei: Int): VoidDiscard the tiles hidden by break-on-match rules (or opaque tiles) in given area
| Name | Type |
|---|---|
cache |
AutoTileCache |
rulesEvalOrder |
Array<RuleDef> |
cx |
Int |
cy |
Int |
wid |
Int |
hei |
Int |
new(source: RuleSource, target: RuleTarget, tileset: RuleTileset): Void| Name | Type |
|---|---|
source |
RuleSource |
target |
RuleTarget |
tileset |
RuleTileset |
Private Members
mapSink: MapAutoTileCachelocks: haxe.ds.Vector<Bool>addedTiles: IntaddedOpaque: BooltrackOpaque: Bool| Name | Type |
|---|---|
a |
Int |
b |
Int |
| Returns |
|---|
| Int |
| Name | Type |
|---|---|
a |
Int |
b |
Int |
| Returns |
|---|
| Int |
ensureLocks(): VoidCheck a single condition against an IntGrid value: +v = value required, -v = value forbidden, with the "anything" and group special values
| Name | Type |
|---|---|
term |
Int |
value |
Int |
| Returns |
|---|
| Bool |
| Name | Type |
|---|---|
sink |
AutoTileSink |
coordId |
Int |
x |
Int |
y |
Int |
tid |
Int |
flips |
Int |
alpha |
Float |
TRUE if a rule that produced tiles in a cell prevents the following rules from rendering there
| Name | Type |
|---|---|
r |
RuleDef |
| Returns |
|---|
| Bool |
computeCells(sink: AutoTileSink, rulesEvalOrder: Array<RuleDef>, left: Int, top: Int, right: Int, bottom: Int): VoidShared runtime loop: rules in evaluation order, cells of the rectangle (inclusive bounds) row by row, locks applied on the fly
| Name | Type |
|---|---|
sink |
AutoTileSink |
rulesEvalOrder |
Array<RuleDef> |
left |
Int |
top |
Int |
right |
Int |
bottom |
Int |