Pin the y-sort origin to the centred chunk row
Tim Falken authored 2 months ago
The origin was the viewport centre, so it moved every frame and forced a
re-layer of the whole static world to stay consistent with entities. Quantise
it to the chunk row under the view instead: it only moves when the view
crosses a chunk border, and only then does #refreshDepthLayers run. Relative
sortY stays well inside LAYER_EDGE because chunks span the static 5x5 ring.
Layer writes now go through #setLayer, which skips the write when the value
is unchanged. A layer write costs the scene a full activeObjects sort, so a
frame in which nothing changes draw order no longer sorts at all.
Co-authored-by: Cursor <cursoragent@cursor.com>