A zoom goes from the ghost straight to the map, never through black

Zooming in showed the ghost, then a black screen, then the map drawn in. The
black was a raster started the moment the view changed, before the new tile
zoom's tiles had loaded. It had nothing to draw, and being the view's own
frame it replaced the ghost. On the PicoCalc it stayed up 0.4 to 1.0 s, and
sometimes a half-drawn frame followed it before the real one. The same
happened when the map first opened.

The map now starts no raster while a tile of its view is still on its way.
It keeps standing on what it has (the aligned frame, or the ghost), and the
first raster it draws is the real picture. A tile that comes back as silence
is no longer on its way, so a map with no network still draws what it can.

Measured with a zoom tour on the PicoCalc: in to z11, z12 and z13, then back
out to z10. Before, every zoom across a tile zoom published a raster with
none of its tiles. Now each zoom draws one raster with all of them. The
finished picture arrives as soon as it did before (0.8 to 1.35 s in, 0.4 to
0.7 s out), with 6 rasters drawn instead of 13.

Tests that exercised raster scheduling now let their tiles answer first,
since a captured load used to stay on its way for ever.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-10-04 17:49:24 -04:00
1 parent af815cf2f2
commit 858053f5fa
3 files changed
+92 -16

No files matched your search

+14 -2
View File
@@ -433,8 +433,16 @@ class MapScreen(Screen):
keys exactly, and the streets slide with the view — dimmed, and short of the
edge you are panning onto — instead of the map blanking to black between every
keypress and flashing back when the frame lands (JP, 2026-08-09).
* **A tile this view shows is still on its way** — draw nothing yet. A raster now
would paint that tile's ground black, and being *this* view's frame it would
replace the ghost, so a zoom read as the ghost, then a black screen, then the map
drawn in (JP, 2026-10-04). It was also a raster thrown away: the tile's arrival
asks for another. So the screen keeps standing on what it has — the aligned frame,
or the ghost — until the tiles are in, and the next raster, which is the first, is
the real picture. A tile that comes back as silence is no longer on its way, so a
map with no network still draws what it can.
The last of those is where the map goes black *and stays black*: four coarse pan
The third of those is where the map goes black *and stays black*: four coarse pan
steps are 120% of the screen, so nothing drawn is under the view any more and
there is no ground to reproject. The answer to that is not this method but the one
it schedules — :meth:`_draw_ground` can land a rough picture in a quarter of the
@@ -447,7 +455,11 @@ class MapScreen(Screen):
self._schedule_ground(key, vp) # the first pass is on screen; finish it
return list(self._frame)
self._schedule_ground(key, vp)
if any(t in self._pending for t in vp.tiles(self._max_tile_zoom)):
# Waiting on this view's tiles, so anything queued is for a view already left.
self._wanted = None
else:
self._schedule_ground(key, vp)
if self._aligned(key) and self._frame is not None:
return list(self._frame) # same view, only tiles differ — still aligned
# The view moved (or nothing has ever been drawn): markers over the last ground.
+5 -1
View File
@@ -568,7 +568,11 @@ async def test_location_picker_keeps_the_crosshair_when_the_basemap_lands(
monkeypatch.setattr(ms.asyncio, "ensure_future", coros.append)
screen = _picker(initial=(45.5, -73.6))
screen.render_body(80) # paints now, schedules the ground raster
screen.render_body(80) # paints now, asks for the view's tiles
for load in coros: # the (offline) source answers; no raster until it has
await load
coros.clear()
screen.render_body(80) # paints again, and now schedules the ground raster
assert coros, "no background raster was scheduled"
await coros[-1] # the raster finishes — long after the crosshair was taken back
+73 -13
View File
@@ -2155,6 +2155,25 @@ def _map_over(source) -> MapScreen: # noqa: ANN001
return MapScreen(_StubSession(80, 24), [MapMarker("A", 45.5, -73.6)], source, 14)
async def _drawn(screen) -> None: # noqa: ANN001
"""Paint until the view's tiles have answered and its raster has landed.
Real sleeps, not ``sleep(0)``: a tile load goes through a thread. And no raster is
asked for while a tile of the view is on its way, so a test of the raster has to let
the loads finish first — the stub sources answer at once, with silence.
"""
for _ in range(400):
screen.render_body(80)
if (
not screen._pending
and screen._drawing is None
and screen._frame_key == screen._ground_key(screen._viewport)
):
return
await asyncio.sleep(0.005)
raise AssertionError("the view's ground never landed")
class _SilentSource(_StubSource):
"""A source that never answers — the flaky Wi-Fi, not an empty planet."""
@@ -2595,9 +2614,7 @@ def test_map_skips_the_coarse_pass_over_a_picture_already_drawn(monkeypatch) ->
)
async def drive() -> None:
screen.render_body(80)
while screen._drawing is not None:
await asyncio.sleep(0)
await _drawn(screen)
coarse_asked.clear()
# A tile lands: same view, more detail. The frame on screen is still aligned.
screen._tiles[screen._viewport.tiles(14)[0]] = _loaded_tile()
@@ -2629,12 +2646,7 @@ def test_the_rough_pass_is_a_switch_the_map_reads(monkeypatch) -> None: # noqa:
)
screen = _map_over(_StubSource())
async def drive() -> None:
screen.render_body(80)
while screen._drawing is not None:
await asyncio.sleep(0)
asyncio.run(drive())
asyncio.run(_drawn(screen))
return asked
monkeypatch.setattr(ms, "_COARSE_PREVIEW", True)
@@ -2663,9 +2675,7 @@ def test_map_keeps_its_detail_while_a_find_is_typed(monkeypatch) -> None: # noq
)
async def drive() -> None:
screen.render_body(80)
while screen._drawing is not None:
await asyncio.sleep(0)
await _drawn(screen)
coarse_asked.clear()
screen.handle("text", "a") # one letter of a find query; the view does not move
screen.render_body(80)
@@ -2680,7 +2690,11 @@ def test_map_keeps_its_detail_while_a_find_is_typed(monkeypatch) -> None: # noq
def _async_map(monkeypatch, drawn: list):
"""A map screen whose rasters are captured instead of run, with a live event loop."""
"""A map screen whose rasters are captured instead of run, with a live event loop.
Its tile loads answer the moment they are asked, with silence: a captured load would
otherwise be on its way for ever, and no raster is asked for while one is.
"""
from meshterm.ui import map_screen as ms
from meshterm.ui.map_render import MapMarker
@@ -2689,6 +2703,13 @@ def _async_map(monkeypatch, drawn: list):
monkeypatch.setattr(
ms.asyncio, "ensure_future", lambda coro: (coro.close(), started.append(coro))[0]
)
def answered_at_once(self, t): # noqa: ANN001 - MapScreen._load, minus the thread
self._pending.discard(t)
self._unanswered[t] = monotonic() + _TILE_RETRY
return asyncio.sleep(0) # a coroutine for the captured ensure_future to close
monkeypatch.setattr(ms.MapScreen, "_load", answered_at_once)
screen = ms.MapScreen(_StubSession(80, 24), [MapMarker("A", 45.5, -73.6)], _StubSource(), 14)
drawn.append(started)
return screen
@@ -2762,6 +2783,45 @@ def test_map_holds_an_aligned_frame_while_a_tile_lands(monkeypatch) -> None: #
assert screen._drawing is not None, "did not redraw for the new tile"
def test_map_stands_on_its_ghost_until_the_view_tiles_are_in(monkeypatch) -> None: # noqa: ANN001
"""A zoom shows the ghost, then the map — never a black screen in between.
A raster drawn while the new zoom's tiles were still loading painted their ground
black, and being the view's own frame it replaced the ghost: ghost, black, then the
streets drawn in (JP, 2026-10-04). It was a raster thrown away besides, since the tiles
landing ask for another.
"""
from meshterm.ui import map_screen as ms
from meshterm.ui.map_render import MapMarker
monkeypatch.setattr(ms, "_loop_running", lambda: True)
started: list = []
monkeypatch.setattr(
ms.asyncio, "ensure_future", lambda coro: (coro.close(), started.append(coro))[0]
)
stood_on: list = []
monkeypatch.setattr(
ms, "render_map", lambda vp, tiles, m, **k: stood_on.append(k.get("ghost")) or [""]
)
screen = ms.MapScreen(_StubSession(80, 24), [MapMarker("A", 45.5, -73.6)], _StubSource(), 14)
screen._ghost = ghost = object() # the ground the last view left behind
def rasters() -> list:
return [c for c in started if "_draw_ground" in c.__qualname__]
screen.handle("pageup") # zoom in: a tile zoom whose tiles are not in hand
screen.render_body(80)
assert screen._pending, "the fixture's view asked for no tiles"
assert not rasters(), "a raster was drawn before the view's tiles were in"
assert stood_on == [ghost], "the paint did not stand on the ghost"
for t in list(screen._pending): # the tiles land
screen._pending.discard(t)
screen._tiles[t] = _loaded_tile()
screen.render_body(80)
assert len(rasters()) == 1, "the tiles landed and their raster was not drawn"
def test_map_drops_a_stale_frame_once_the_view_moves(monkeypatch) -> None: # noqa: ANN001
"""Streets drawn for somewhere else are a lie about where you are looking."""
started: list = []