Table of Contents

Class GridSyncOptimizer

Namespace
MoonBark.GridPlacement.Godot.Infrastructure
Assembly
MoonBark.GridPlacement.Godot.dll

Optimizes synchronization between logical ECS grid state and visual TileMapLayer. Uses hash-based change detection to skip unnecessary syncs, marks 3x3 neighborhoods around changed cells as dirty for proper visual coverage, and groups dirty cells by chunk for batch processing.

This is a pure-logic optimizer that handles the "when" and "what" of TileMap sync. The actual tile source resolution (TileTypeId → Godot tile coords) is handled by TileMapSyncManager which owns the IGridOccupancy reference.

See: docs/core/guides/architecture-overview.md

public class GridSyncOptimizer
Inheritance
GridSyncOptimizer
Inherited Members

Constructors

GridSyncOptimizer(int)

Creates a new GridSyncOptimizer.

public GridSyncOptimizer(int chunkSize = 16)

Parameters

chunkSize int

Chunk size for grouping dirty cells. Default is 16.

Properties

ChunkSize

Chunk size for grouping dirty cells. Larger chunks = fewer TileMap API calls but more cells processed per chunk.

public int ChunkSize { get; }

Property Value

int

Methods

HasOccupancyChanged(HashSet<CoreVector2I>)

Checks if the occupied cells have changed since the last check. Uses an order-independent hash (count ^ xorHash ^ sumX ^ sumY) for comparison.

public bool HasOccupancyChanged(HashSet<CoreVector2I> occupiedCells)

Parameters

occupiedCells HashSet<CoreVector2I>

The current set of occupied grid positions.

Returns

bool

True if the occupied cells differ from the last check; false if identical.

Reset()

Resets the cached state, causing the next sync to treat all cells as new.

public void Reset()

SyncToTileMapLayer(HashSet<CoreVector2I>, TileMapLayer)

Synchronizes the occupied cells to the TileMapLayer. Computes dirty cells (3x3 neighborhood around changed cells), groups them by chunk, and sets or clears tiles accordingly.

public bool SyncToTileMapLayer(HashSet<CoreVector2I> occupiedCells, TileMapLayer tileMapLayer)

Parameters

occupiedCells HashSet<CoreVector2I>

The current set of occupied grid positions.

tileMapLayer TileMapLayer

The TileMapLayer to synchronize to.

Returns

bool

True if a sync was performed; false if the occupied cells matched the last sync.