MapSquare.decode_locs reverses the loc list twice, and interaction targeting depends on it #24
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Cache.MapSquare.decode_locs/1reverses the loc list twice, and the two cancel.locs/3accumulates withacc ++ Enum.reverse(placed), which is in file order,and then returns
Enum.reverse(acc)— so the decoded list is in reverse fileorder.
World.Collision.index_locs/3then builds each tile's list withMap.update(acc, key, [entry], &[entry | &1]), prepending, which reverses itagain.
World.Collision.locs_at/1therefore returns file order by accident.That ordering is load-bearing.
World.object_shape/2andtoggle_door/6bothresolve a click with
Enum.find/2overlocs_at/1, so when several locs share atile, the order decides which one the player interacted with. Correcting either
reversal on its own — and both look like plain bugs in isolation — silently
changes interaction targeting across the world with nothing failing.
Separately,
acc ++ ...inside the loop is quadratic in the number of loc ids ona square. Squares carry a few thousand locs and the world has 1,513 of them.
Shape of a fix
Build the list in one direction, drop the compensating reverse, and pin the
resulting order with a test that decodes a known multi-loc tile and asserts
which loc a click resolves to.