fix(runtime): bound camera resolver work and handle extreme coordinates
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good

Preserve camera hysteresis with constant-time wide arithmetic, refresh nonoverlapping cache jumps, and clip wide offsets before drawing. Add guest pixel-oracle and resource/snapshot regressions and document the contract.

Validated by the complete tooling verify run 20261126T113331Z-1d071c1d (all 11 stages passed), plus focused debug/release tests. Work: WRK-0020.
This commit is contained in:
2026-11-26 11:47:32 +00:00
parent 7fd6fef1c8
commit 0d20194aa2
6 changed files with 1020 additions and 103 deletions
+79 -13
View File
@@ -401,23 +401,89 @@ It stores tiles already resolved from the tilemap.
## 9. Cache Update
Every frame:
Every camera update MUST materialize all newly exposed tiles before scene
composition. The resolver owns the master anchor, per-layer anchors, hysteresis
and refresh requests; the cache owns the materialized entries and ring mapping.
Scene and glyph banks retain their canonical content and resident identity.
1. Calculate:
- `tile_x = scroll_x / tile_size`
- `tile_y = scroll_y / tile_size`
- `offset_x = scroll_x % tile_size`
- `offset_y = scroll_y % tile_size`
### 9.1 Coordinates and numeric domain
2. If `tile_x` changed:
- Advance `cache_origin_x`
- Reload only the new column
`composer.set_camera(x, y)` accepts signed Int32 top-left pixel coordinates,
including negative values, both extremes and positions outside the scene. The
requested coordinates remain unchanged in closed Game 2D packets and snapshots.
Clamping a cache anchor MUST NOT clamp the requested camera or its public domain.
3. If `tile_y` changed:
- Advance `cache_origin_y`
- Reload only the new line
Each layer retains the existing parallax transformation:
Only **one row and/or column** is updated per frame.
```text
layer_camera = Int32_saturating(floor(f32(camera) * parallax_factor))
```
This includes the existing f32 quantization and saturating conversion. Finite
negative and large factors remain admitted; asset validation rejects nonfinite
input factors. Changing the multiplication to f64 changes this transformation
and is not part of coordinate-overflow handling. Admitted empty scene axes and
u32 scene dimensions MUST NOT produce invalid clamp bounds.
Centers, drift, scene/cache bounds, pixel-origin products and source offsets
MUST use a sufficiently wide integer representation; the current implementation
uses Int64 for these calculations and for `LayerCopyRequest` source offsets.
The guest ABI, asset layout and Game 2D packet layout remain unchanged.
The Gfx consumer computes tile-local screen coordinates in the wide domain. For
an axis with local tile coordinate `p`, tile size `t` and screen extent `s`, it
discards the tile if `p >= s` or `p + t <= 0`, before narrowing for pixel drawing.
A surviving tile satisfies `-t < p < s`; for the native 640×360 viewport and
tiles up to 32 pixels these local coordinates and subsequent pixel additions
fit Int32. Distant off-scene positions MUST NOT overflow while being clipped.
### 9.2 Anchor movement and hysteresis
The first update selects each anchor using Euclidean floor division of its
camera center by tile size, then clamps the anchor to the scene/cache bounds.
Subsequent updates preserve the previous anchor until its hysteresis stopping
bands are exceeded. In particular, selecting an anchor afresh from the camera
every frame is not equivalent: the anchor may depend on camera history.
For tile size `t`, previous anchor `a` and wide camera center `c`, the equivalent
bounded transition for an axis is:
```text
B = max(hysteresis_safe, hysteresis_trigger, t / 2)
d = c - (a * t + t / 2)
if abs(d) <= B: retain a
otherwise: a += sign(d) * ceil((abs(d) - B) / t)
then clamp the anchor using wide scene/cache bounds
```
Runtime hysteresis thresholds are nonnegative. The half-tile floor prevents
mixed-size layers from stepping past the center and immediately stepping back.
Anchor advancement MUST perform bounded arithmetic per axis/layer, without
walking tiles in proportion to raw camera distance.
### 9.3 Partial refresh and jumps
For a layer cache of `w × h` tiles and anchor displacement `(dx, dy)`:
- Initialization, scene reset and existing invalidations retain their full
materialization behavior.
- If `abs(dx) >= w` or `abs(dy) >= h`, the old and new windows have no overlap.
Refresh the full region of that layer once.
- With overlap, refresh only the newly exposed rows, columns or corner strips.
Corner strips MUST NOT materialize their intersection twice.
- Without displacement or invalidation, no refresh is required.
Move the logical ring window before applying its refresh requests. All indices
and regions MUST lie within the cache. Fast movement can expose multiple rows
or columns in one frame; a jump can require the full window. A one-row/column
limit MUST NOT leave newly exposed tiles stale.
For overlapping diagonal movement, the exposed area is
`abs(dx) * h + (w - abs(dx)) * abs(dy)`, at most `w * h`. Consequently a camera
update materializes at most the sum of the four layer-cache areas, and emits a
number of requests bounded by cache geometry. There are two master-axis and
eight layer-axis calculations. These limits are independent of raw camera
distance; they do not bound guest execution or asset loading costs.
---